Search in sources :

Example 11 with PythonSdkFlavor

use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.

the class PyActiveSdkConfigurable method rehighlightVersionSpecific.

private void rehighlightVersionSpecific(@Nullable final Sdk newSdk, @Nullable final Sdk prevSdk) {
    if (prevSdk != null && newSdk != null) {
        final PythonSdkFlavor flavor1 = PythonSdkFlavor.getFlavor(newSdk);
        final PythonSdkFlavor flavor2 = PythonSdkFlavor.getFlavor(prevSdk);
        if (flavor1 != null && flavor2 != null) {
            final LanguageLevel languageLevel1 = flavor1.getLanguageLevel(newSdk);
            final LanguageLevel languageLevel2 = flavor2.getLanguageLevel(prevSdk);
            if ((languageLevel1.isPy3K() && !languageLevel2.isPy3K()) || (!languageLevel1.isPy3K()) && languageLevel2.isPy3K()) {
                PyUtil.rehighlightOpenEditors(myProject);
            }
        }
    }
}
Also used : LanguageLevel(com.jetbrains.python.psi.LanguageLevel) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor)

Example 12 with PythonSdkFlavor

use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.

the class PyConfigurableInterpreterList method addDetectedSdks.

private void addDetectedSdks(@NotNull final List<Sdk> result) {
    final List<String> sdkHomes = new ArrayList<>();
    sdkHomes.addAll(VirtualEnvSdkFlavor.INSTANCE.suggestHomePaths());
    for (PythonSdkFlavor flavor : PythonSdkFlavor.getApplicableFlavors()) {
        if (flavor instanceof VirtualEnvSdkFlavor)
            continue;
        sdkHomes.addAll(flavor.suggestHomePaths());
    }
    Collections.sort(sdkHomes);
    for (String sdkHome : SdkConfigurationUtil.filterExistingPaths(PythonSdkType.getInstance(), sdkHomes, getModel().getSdks())) {
        result.add(new PyDetectedSdk(sdkHome));
    }
}
Also used : PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) ArrayList(java.util.ArrayList) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) VirtualEnvSdkFlavor(com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor)

Example 13 with PythonSdkFlavor

use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.

the class PyStudyDirectoryProjectGenerator method getBaseSdk.

private static String getBaseSdk(@NotNull final Project project) {
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    LanguageLevel baseLevel = LanguageLevel.PYTHON30;
    if (course != null) {
        final String version = course.getLanguageVersion();
        if (PyStudyLanguageManager.PYTHON_2.equals(version)) {
            baseLevel = LanguageLevel.PYTHON27;
        } else if (PyStudyLanguageManager.PYTHON_3.equals(version)) {
            baseLevel = LanguageLevel.PYTHON31;
        } else if (version != null) {
            baseLevel = LanguageLevel.fromPythonVersion(version);
        }
    }
    final PythonSdkFlavor flavor = PythonSdkFlavor.getApplicableFlavors(false).get(0);
    String baseSdk = null;
    final Collection<String> baseSdks = flavor.suggestHomePaths();
    for (String sdk : baseSdks) {
        final String versionString = flavor.getVersionString(sdk);
        final String prefix = flavor.getName() + " ";
        if (versionString != null && versionString.startsWith(prefix)) {
            final LanguageLevel level = LanguageLevel.fromPythonVersion(versionString.substring(prefix.length()));
            if (level.isAtLeast(baseLevel)) {
                baseSdk = sdk;
                break;
            }
        }
    }
    return baseSdk != null ? baseSdk : baseSdks.iterator().next();
}
Also used : LanguageLevel(com.jetbrains.python.psi.LanguageLevel) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) Course(com.jetbrains.edu.learning.courseFormat.Course)

Example 14 with PythonSdkFlavor

use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.

the class PyDebugRunner method createDebugServerPatcher.

private CommandLinePatcher createDebugServerPatcher(final Project project, final PythonCommandLineState pyState, final int serverLocalPort) {
    return new CommandLinePatcher() {

        private void patchExeParams(ParametersList parametersList) {
            // we should remove '-m' parameter, but notify debugger of it
            // but we can't remove one parameter from group, so we create new parameters group
            ParamsGroup newExeParams = new ParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
            int exeParamsIndex = parametersList.getParamsGroups().indexOf(parametersList.getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS));
            ParamsGroup exeParamsOld = parametersList.removeParamsGroup(exeParamsIndex);
            isModule = false;
            for (String param : exeParamsOld.getParameters()) {
                if (!param.equals("-m")) {
                    newExeParams.addParameter(param);
                } else {
                    isModule = true;
                }
            }
            parametersList.addParamsGroupAt(exeParamsIndex, newExeParams);
        }

        @Override
        public void patchCommandLine(GeneralCommandLine commandLine) {
            // script name is the last parameter; all other params are for python interpreter; insert just before name
            ParametersList parametersList = commandLine.getParametersList();
            @SuppressWarnings("ConstantConditions") @NotNull ParamsGroup debugParams = parametersList.getParamsGroup(PythonCommandLineState.GROUP_DEBUGGER);
            patchExeParams(parametersList);
            @SuppressWarnings("ConstantConditions") @NotNull ParamsGroup exeParams = parametersList.getParamsGroup(PythonCommandLineState.GROUP_EXE_OPTIONS);
            final PythonSdkFlavor flavor = pyState.getSdkFlavor();
            if (flavor != null) {
                assert exeParams != null;
                for (String option : flavor.getExtraDebugOptions()) {
                    exeParams.addParameter(option);
                }
            }
            assert debugParams != null;
            fillDebugParameters(project, debugParams, serverLocalPort, pyState, commandLine);
        }
    };
}
Also used : CommandLinePatcher(com.jetbrains.python.run.CommandLinePatcher) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with PythonSdkFlavor

use of com.jetbrains.python.sdk.flavors.PythonSdkFlavor in project intellij-community by JetBrains.

the class PyUnitTestTask method runConfiguration.

protected void runConfiguration(ConfigurationFactory factory, String sdkHome, final Project project) throws Exception {
    final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createRunConfiguration("test", factory);
    AbstractPythonLegacyTestRunConfiguration config = (AbstractPythonLegacyTestRunConfiguration) settings.getConfiguration();
    config.setSdkHome(sdkHome);
    config.setScriptName(getScriptName());
    config.setWorkingDirectory(myFixture.getTempDirPath());
    PythonSdkFlavor sdk = PythonSdkFlavor.getFlavor(sdkHome);
    if (sdk instanceof JythonSdkFlavor) {
        config.setInterpreterOptions(JythonSdkFlavor.getPythonPathCmdLineArgument(Lists.<String>newArrayList(myFixture.getTempDirPath())));
    } else {
        PythonEnvUtil.addToPythonPath(config.getEnvs(), myFixture.getTempDirPath());
    }
    configure(config);
    new WriteAction() {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            RunManagerEx.getInstanceEx(project).addConfiguration(settings, false);
            RunManagerEx.getInstanceEx(project).setSelectedConfiguration(settings);
            Assert.assertSame(settings, RunManagerEx.getInstanceEx(project).getSelectedConfiguration());
        }
    }.execute();
    runConfiguration(settings, config);
}
Also used : JythonSdkFlavor(com.jetbrains.python.sdk.flavors.JythonSdkFlavor) WriteAction(com.intellij.openapi.application.WriteAction) PythonSdkFlavor(com.jetbrains.python.sdk.flavors.PythonSdkFlavor) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AbstractPythonLegacyTestRunConfiguration(com.jetbrains.python.testing.AbstractPythonLegacyTestRunConfiguration) Result(com.intellij.openapi.application.Result)

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