diff --git a/python/educational-python/Edu-Python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java b/python/educational-python/Edu-Python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java index e2e84390f4a0..1bbbc4401cb6 100644 --- a/python/educational-python/Edu-Python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java +++ b/python/educational-python/Edu-Python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java @@ -135,8 +135,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks(); + final List sdks = PyConfigurableInterpreterList.getInstance(null).getAllPythonSdks(); ValidationResult validationResult; if (sdks.isEmpty()) { @@ -178,8 +177,7 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator getLanguageSettingsComponent(@NotNull Course selectedCourse) { - final Project project = ProjectManager.getInstance().getDefaultProject(); - final List sdks = PyConfigurableInterpreterList.getInstance(project).getAllPythonSdks(); + final List sdks = PyConfigurableInterpreterList.getInstance(null).getAllPythonSdks(); VirtualEnvProjectFilter.removeAllAssociated(sdks); // by default we create new virtual env in project, we need to add this non-existing sdk to sdk list ProjectJdkImpl fakeSdk = createFakeSdk(selectedCourse); diff --git a/python/python-community-configure/src/com/jetbrains/python/configuration/PyConfigurableInterpreterList.java b/python/python-community-configure/src/com/jetbrains/python/configuration/PyConfigurableInterpreterList.java index a05db69f0b38..c06daf8d1ee8 100644 --- a/python/python-community-configure/src/com/jetbrains/python/configuration/PyConfigurableInterpreterList.java +++ b/python/python-community-configure/src/com/jetbrains/python/configuration/PyConfigurableInterpreterList.java @@ -17,6 +17,7 @@ package com.jetbrains.python.configuration; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; import com.intellij.openapi.util.Comparing; @@ -40,8 +41,13 @@ import java.util.List; public class PyConfigurableInterpreterList { private ProjectSdksModel myModel; - public static PyConfigurableInterpreterList getInstance(Project project) { - return ServiceManager.getService(project, PyConfigurableInterpreterList.class); + public static PyConfigurableInterpreterList getInstance(@Nullable Project project) { + final Project effectiveProject = project != null ? project : ProjectManager.getInstance().getDefaultProject(); + final PyConfigurableInterpreterList instance = ServiceManager.getService(effectiveProject, PyConfigurableInterpreterList.class); + if (effectiveProject != project) { + instance.disposeModel(); + } + return instance; } public ProjectSdksModel getModel() { diff --git a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonSdkChooserCombo.java b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonSdkChooserCombo.java index 6a9c9952902a..b13056caecda 100644 --- a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonSdkChooserCombo.java +++ b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonSdkChooserCombo.java @@ -17,7 +17,6 @@ package com.jetbrains.python.newProject.steps; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.project.DefaultProjectFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel; @@ -79,8 +78,7 @@ public class PythonSdkChooserCombo extends ComboboxWithBrowseButton { } private void showOptions(@Nullable final Project project) { - final Project existingProject = project != null ? project : DefaultProjectFactory.getInstance().getDefaultProject(); - final PyConfigurableInterpreterList interpreterList = PyConfigurableInterpreterList.getInstance(existingProject); + final PyConfigurableInterpreterList interpreterList = PyConfigurableInterpreterList.getInstance(project); final Sdk[] sdks = interpreterList.getModel().getSdks(); //noinspection unchecked final JComboBox comboBox = getComboBox();