Search in sources :

Example 6 with PythonSdkFlavor

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));
}
Also used : UnixPythonSdkFlavor(com.jetbrains.python.sdk.flavors.UnixPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 7 with PythonSdkFlavor

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;
}
Also used : CPythonSdkFlavor(com.jetbrains.python.sdk.flavors.CPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with PythonSdkFlavor

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;
}
Also used : CPythonSdkFlavor(com.jetbrains.python.sdk.flavors.CPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) NonNls(org.jetbrains.annotations.NonNls) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PythonSdkFlavor

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());
}
Also used : CPythonSdkFlavor(com.jetbrains.python.sdk.flavors.CPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) CPythonSdkFlavor(com.jetbrains.python.sdk.flavors.CPythonSdkFlavor)

Example 10 with PythonSdkFlavor

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);
}
Also used : IronPythonSdkFlavor(com.jetbrains.python.sdk.flavors.IronPythonSdkFlavor) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) IronPythonSdkFlavor(com.jetbrains.python.sdk.flavors.IronPythonSdkFlavor) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

PythonSdkFlavor (com.jetbrains.python.sdk.flavors.PythonSdkFlavor)18 Sdk (com.intellij.openapi.projectRoots.Sdk)9 UnixPythonSdkFlavor (com.jetbrains.python.sdk.flavors.UnixPythonSdkFlavor)6 CPythonSdkFlavor (com.jetbrains.python.sdk.flavors.CPythonSdkFlavor)4 LanguageLevel (com.jetbrains.python.psi.LanguageLevel)2 Nullable (org.jetbrains.annotations.Nullable)2 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LayeredIcon (com.intellij.ui.LayeredIcon)1 Course (com.jetbrains.edu.learning.courseFormat.Course)1 CommandLinePatcher (com.jetbrains.python.run.CommandLinePatcher)1 PyDetectedSdk (com.jetbrains.python.sdk.PyDetectedSdk)1 IronPythonSdkFlavor (com.jetbrains.python.sdk.flavors.IronPythonSdkFlavor)1 JythonSdkFlavor (com.jetbrains.python.sdk.flavors.JythonSdkFlavor)1 VirtualEnvSdkFlavor (com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor)1 AbstractPythonLegacyTestRunConfiguration (com.jetbrains.python.testing.AbstractPythonLegacyTestRunConfiguration)1 ArrayList (java.util.ArrayList)1 NonNls (org.jetbrains.annotations.NonNls)1