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);
}
}
}
}
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));
}
}
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();
}
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);
}
};
}
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);
}
Aggregations