From 8fab03be0d0361f2ba3944c29cb8e79db32416c7 Mon Sep 17 00:00:00 2001 From: Semyon Proshev Date: Fri, 30 Jul 2021 19:19:27 +0300 Subject: [PATCH] Simplify checking if sdk is editable (PY-45708) GitOrigin-RevId: 04e98dd7a85a62ddd0b48ad149f6d16780496ea9 --- .../src/com/jetbrains/python/sdk/PythonSdkUpdater.java | 4 ++-- .../testSrc/com/jetbrains/python/sdk/PySdkPathsTest.kt | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java index 2572a5932978..51ce72e7a0d7 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkUpdater.java @@ -34,13 +34,13 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ArrayUtil; import com.intellij.util.ExceptionUtil; import com.intellij.util.PathMappingSettings; import com.intellij.util.Processor; import com.jetbrains.python.PyBundle; import com.jetbrains.python.codeInsight.typing.PyTypeShed; import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil; -import com.jetbrains.python.configuration.PyConfigurableInterpreterList; import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.psi.PyUtil; import com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase; @@ -417,7 +417,7 @@ public class PythonSdkUpdater implements StartupActivity.Background { When current method was executed for original sdk, roots changes were not applied since there were no changes in paths to transfer (they were shared with editable copy). */ - if (PyConfigurableInterpreterList.getInstance(project).getModel().getProjectSdks().containsKey(sdk) && + if (ArrayUtil.contains(sdk, ProjectJdkTable.getInstance().getAllJdks()) && !pathsToTransfer.equals(PyTransferredSdkRootsKt.getPathsToTransfer(sdk))) { if (project != null) { PyTransferredSdkRootsKt.removeTransferredRootsFromModulesWithSdk(project, sdk); diff --git a/python/testSrc/com/jetbrains/python/sdk/PySdkPathsTest.kt b/python/testSrc/com/jetbrains/python/sdk/PySdkPathsTest.kt index 453c2243f640..6fc21d9785fc 100644 --- a/python/testSrc/com/jetbrains/python/sdk/PySdkPathsTest.kt +++ b/python/testSrc/com/jetbrains/python/sdk/PySdkPathsTest.kt @@ -134,11 +134,10 @@ class PySdkPathsTest { ) .also { module.pythonSdk = it } sdk.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion) - Disposer.register(projectModel.project, sdk) mockPythonPluginDisposable() runWriteActionAndWait { sdk.getOrCreateAdditionalData() } - PyConfigurableInterpreterList.getInstance(projectModel.project).model.addSdk(sdk) + runWriteActionAndWait { ProjectJdkTable.getInstance().addJdk(sdk) } val editableSdk = PyConfigurableInterpreterList.getInstance(projectModel.project).model.findSdk(sdk.name) editableSdk!!.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion) @@ -165,6 +164,8 @@ class PySdkPathsTest { updateSdkPaths(sdk) // since editableSdk was created after additional data had been created for sdk, they share the same data checkRoots(sdk, module, listOf(moduleRoot), emptyList()) + + runWriteActionAndWait { ProjectJdkTable.getInstance().removeJdk(sdk) } } @Test @@ -186,8 +187,7 @@ class PySdkPathsTest { ) .also { module.pythonSdk = it } sdk.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion) - Disposer.register(projectModel.project, sdk) - PyConfigurableInterpreterList.getInstance(projectModel.project).model.addSdk(sdk) + runWriteActionAndWait { ProjectJdkTable.getInstance().addJdk(sdk) } val editableSdk = PyConfigurableInterpreterList.getInstance(projectModel.project).model.findSdk(sdk.name) editableSdk!!.putUserData(PythonSdkType.MOCK_PY_VERSION_KEY, pythonVersion) @@ -220,6 +220,8 @@ class PySdkPathsTest { updateSdkPaths(sdk) // after updateJdk call editableSdk and sdk share the same data checkRoots(sdk, module, listOf(moduleRoot), emptyList()) + + runWriteActionAndWait { ProjectJdkTable.getInstance().removeJdk(sdk) } } @Test