use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.
the class PySdkFlavorTest method testJython25WithWarningsVersionString.
public void testJython25WithWarningsVersionString() {
final PythonSdkFlavor flavor = JythonSdkFlavor.INSTANCE;
final String versionOutput = "\"my\" variable $jythonHome masks earlier declaration in same scope at /usr/bin/jython line 15.\n" + "Jython 2.5.3\n";
final Sdk mockSdk = createMockSdk(flavor, versionOutput);
assertEquals("Jython 2.5.3", mockSdk.getVersionString());
assertEquals(LanguageLevel.PYTHON25, flavor.getLanguageLevel(mockSdk));
}
use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.
the class PythonSdkType method getVirtualEnvBaseSdk.
@Nullable
public Sdk getVirtualEnvBaseSdk(Sdk sdk) {
if (isVirtualEnv(sdk)) {
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(sdk);
final String version = getVersionString(sdk);
if (flavor != null && version != null) {
for (Sdk baseSdk : getAllSdks()) {
if (!isRemote(baseSdk)) {
final PythonSdkFlavor baseFlavor = PythonSdkFlavor.getFlavor(baseSdk);
if (!isVirtualEnv(baseSdk) && flavor.equals(baseFlavor) && version.equals(getVersionString(baseSdk))) {
return baseSdk;
}
}
}
}
}
return null;
}
use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.
the class PythonSdkType method suggestHomePath.
@NonNls
@Nullable
public String suggestHomePath() {
final String pythonFromPath = findPythonInPath();
if (pythonFromPath != null) {
return pythonFromPath;
}
for (PythonSdkFlavor flavor : PythonSdkFlavor.getApplicableFlavors()) {
TreeSet<String> candidates = createVersionSet();
candidates.addAll(flavor.suggestHomePaths());
if (!candidates.isEmpty()) {
// return latest version
String[] candidateArray = ArrayUtil.toStringArray(candidates);
return candidateArray[candidateArray.length - 1];
}
}
return null;
}
use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.
the class PreferredSdkComparator method compare.
@Override
public int compare(Sdk o1, Sdk o2) {
final PythonSdkFlavor flavor1 = PythonSdkFlavor.getFlavor(o1);
final PythonSdkFlavor flavor2 = PythonSdkFlavor.getFlavor(o2);
int remote1Weight = PySdkUtil.isRemote(o1) ? 0 : 1;
int remote2Weight = PySdkUtil.isRemote(o2) ? 0 : 1;
if (remote1Weight != remote2Weight) {
return remote2Weight - remote1Weight;
}
int detectedWeight1 = o1 instanceof PyDetectedSdk ? 0 : 1;
int detectedWeight2 = o2 instanceof PyDetectedSdk ? 0 : 1;
if (detectedWeight1 != detectedWeight2) {
return detectedWeight2 - detectedWeight1;
}
int venv1weight = PythonSdkType.isVirtualEnv(o1) ? 0 : 1;
int venv2weight = PythonSdkType.isVirtualEnv(o2) ? 0 : 1;
if (venv1weight != venv2weight) {
return venv2weight - venv1weight;
}
int flavor1weight = flavor1 instanceof CPythonSdkFlavor ? 1 : 0;
int flavor2weight = flavor2 instanceof CPythonSdkFlavor ? 1 : 0;
if (flavor1weight != flavor2weight) {
return flavor2weight - flavor1weight;
}
return -Comparing.compare(o1.getVersionString(), o2.getVersionString());
}
use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.
the class GenerateBinaryStubsFix method isApplicable.
/**
* Checks if this fix can help you to generate binary stubs
*
* @param importStatementBase statement to fix
* @return true if this fix could work
*/
public static boolean isApplicable(@NotNull final PyImportStatementBase importStatementBase) {
if (importStatementBase.getFullyQualifiedObjectNames().isEmpty() && !(importStatementBase instanceof PyFromImportStatement && ((PyFromImportStatement) importStatementBase).isStarImport())) {
return false;
}
final Sdk sdk = getPythonSdk(importStatementBase);
if (sdk == null) {
return false;
}
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(sdk);
if (flavor instanceof IronPythonSdkFlavor) {
return true;
}
return isGtk(importStatementBase);
}
Aggregations