From 5b0f17f657608669c73e0c8b4e2169dc9d80fdf8 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Fri, 13 Dec 2019 16:19:46 +0300 Subject: [PATCH] Reduce number of cases when interpreter is not configured (PY-39541) Make PythonSdkConfigurator to be a project listener. It will catch opening project with .idea inside, or from recent projects list, or getting it from vcs. GitOrigin-RevId: fcf3a7a37b4675670fad654efcc786f9f7fe9df1 --- .../pycharm-community-customization.xml | 10 +++++-- .../jetbrains/python/PythonSdkConfigurator.kt | 28 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/python/ide/impl/resources/META-INF/pycharm-community-customization.xml b/python/ide/impl/resources/META-INF/pycharm-community-customization.xml index 8e6c96706edb..2c3fe5e8169a 100644 --- a/python/ide/impl/resources/META-INF/pycharm-community-customization.xml +++ b/python/ide/impl/resources/META-INF/pycharm-community-customization.xml @@ -1,5 +1,5 @@ - + @@ -13,6 +13,12 @@ + + + com.jetbrains.python.PythonSdkConfigurator + + + - ): Sdk? { + private fun findExistingAssociatedSdk(module: Module, existingSdks: List): Sdk? { return existingSdks .asSequence() .filter { it.sdkType is PythonSdkType && it.isAssociatedWithModule(module) } @@ -33,7 +32,7 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator { .firstOrNull() } - fun findDetectedAssociatedEnvironment(module: Module, existingSdks: List, context: UserDataHolder): PyDetectedSdk? { + private fun findDetectedAssociatedEnvironment(module: Module, existingSdks: List, context: UserDataHolder): PyDetectedSdk? { // TODO: Move all interpreter detection away from EDT & use proper synchronization for that val progress = ProgressManager.getInstance() return progress.run(object : Task.WithResult(module.project, @@ -63,12 +62,19 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator { detectSystemWideSdks(module, existingSdks, context).firstOrNull() } - override fun configureProject(project: Project, - baseDir: VirtualFile, - moduleRef: Ref, - newProject: Boolean) { + init { + ApplicationManager.getApplication().messageBus.connect().subscribe(ProjectManager.TOPIC, object : ProjectManagerListener { + override fun projectOpened(project: Project) { + if (!project.isDefault) { + configureSdk(project) + } + } + }) + } + + private fun configureSdk(project: Project) { val context = UserDataHolderBase() - if (project.pythonSdk != null || newProject) { + if (project.pythonSdk != null) { return } val module = ModuleManager.getInstance(project).modules.firstOrNull() ?: return