diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/PythonSdkConfigurator.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/PythonSdkConfigurator.kt index 9f93d90e735a..310ec0672ea1 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/PythonSdkConfigurator.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/PythonSdkConfigurator.kt @@ -36,7 +36,7 @@ import com.jetbrains.python.PyBundle import com.jetbrains.python.getOrLogException import com.jetbrains.python.sdk.* import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer -import com.jetbrains.python.sdk.configuration.CreateSdkInfo +import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool import com.jetbrains.python.sdk.configuration.PyProjectSdkConfiguration.setReadyToUseSdk import com.jetbrains.python.sdk.configuration.PyProjectSdkConfiguration.setSdkUsingCreateSdkInfo import com.jetbrains.python.sdk.configuration.PyProjectSdkConfiguration.suppressTipAndInspectionsFor @@ -98,7 +98,7 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator { ) } - private suspend fun findSuitableCreateSdkInfos(module: Module): List = withContext(Dispatchers.Default) { + private suspend fun findSuitableCreateSdkInfos(module: Module): List = withContext(Dispatchers.Default) { if (!TrustedProjects.isProjectTrusted(module.project) || ApplicationManager.getApplication().isUnitTestMode) { emptyList() } @@ -112,7 +112,7 @@ class PythonSdkConfigurator : DirectoryProjectConfigurator { suspend fun configureSdk( project: Project, module: Module, - createSdkInfos: List, + createSdkInfos: List, ): Unit = withContext(Dispatchers.Default) { val context = UserDataHolderBase() diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/conda/PyEnvironmentYmlSdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/conda/PyEnvironmentYmlSdkConfiguration.kt index 96067699026c..2a7b079219f4 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/conda/PyEnvironmentYmlSdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/conda/PyEnvironmentYmlSdkConfiguration.kt @@ -25,6 +25,7 @@ import com.intellij.util.FileName import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.jetbrains.python.PyBundle import com.jetbrains.python.PyToolUIInfo +import com.jetbrains.python.ToolId import com.jetbrains.python.configuration.PyConfigurableInterpreterList import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.getOrNull @@ -64,10 +65,10 @@ import kotlin.io.path.name @ApiStatus.Internal class PyEnvironmentYmlSdkConfiguration : PyProjectSdkConfigurationExtension { - override val toolInfo: PyToolUIInfo = PyToolUIInfo("Conda", PythonSdkUIIcons.Tools.Anaconda) + override val toolId: ToolId = ToolId("Conda") override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkManageableEnv(module, it) } + { checkManageableEnv(module, it) } ) { envExists -> { needsConfirmation -> createAndAddSdk(module, if (needsConfirmation) Source.CONFIGURATOR else Source.INSPECTION, envExists) } } diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyHatchSdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyHatchSdkConfiguration.kt index 12edc186cd3c..6a19428a75a4 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyHatchSdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyHatchSdkConfiguration.kt @@ -27,16 +27,13 @@ class PyHatchSdkConfiguration : PyProjectTomlConfigurationExtension { private val LOGGER = Logger.getInstance(PyHatchSdkConfiguration::class.java) } - override val toolInfo: PyToolUIInfo = HATCH_UI_INFO override val toolId: ToolId = HATCH_TOOL_ID override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, true) }, ) { envExists -> { createSdk(module, envExists) } } override suspend fun createSdkWithoutPyProjectTomlChecks(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, false) }, ) { envExists -> { createSdk(module, envExists) } } diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPipfileSdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPipfileSdkConfiguration.kt index 942bcd2b2391..97ade8482067 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPipfileSdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPipfileSdkConfiguration.kt @@ -25,6 +25,7 @@ import com.intellij.ui.components.JBLabel import com.intellij.util.ui.JBUI import com.jetbrains.python.PyBundle import com.jetbrains.python.PyToolUIInfo +import com.jetbrains.python.ToolId import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.getOrLogException import com.jetbrains.python.sdk.PythonSdkType @@ -53,10 +54,10 @@ private val LOGGER = Logger.getInstance(PyPipfileSdkConfiguration::class.java) @ApiStatus.Internal class PyPipfileSdkConfiguration : PyProjectSdkConfigurationExtension { - override val toolInfo: PyToolUIInfo = PyToolUIInfo("Pipenv", PythonSdkUIIcons.Tools.Pip) + override val toolId: ToolId = ToolId("pipenv") override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkManageableEnv(module, it) } + { checkManageableEnv(module, it) } ) { envExists -> { needsConfirmation -> createAndAddSdk(module, if (needsConfirmation) Source.CONFIGURATOR else Source.INSPECTION, envExists) } } diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPoetrySdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPoetrySdkConfiguration.kt index bcde30f3ecb3..41a0dc8e0313 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPoetrySdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyPoetrySdkConfiguration.kt @@ -43,16 +43,13 @@ class PyPoetrySdkConfiguration : PyProjectTomlConfigurationExtension { private val LOGGER = Logger.getInstance(PyPoetrySdkConfiguration::class.java) } - override val toolInfo: PyToolUIInfo = POETRY_UI_INFO override val toolId: ToolId = POETRY_TOOL_ID override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, true) }, ) { { createPoetry(module) } } override suspend fun createSdkWithoutPyProjectTomlChecks(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, false) }, ) { { createPoetry(module) } } diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyRequirementsTxtOrSetupPySdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyRequirementsTxtOrSetupPySdkConfiguration.kt index 6d4ab0f33583..dbb0bdfb2743 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyRequirementsTxtOrSetupPySdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyRequirementsTxtOrSetupPySdkConfiguration.kt @@ -21,11 +21,10 @@ import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationC import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationCollector.Source import com.intellij.pycharm.community.ide.impl.configuration.PySdkConfigurationCollector.VirtualEnvResult import com.intellij.pycharm.community.ide.impl.configuration.ui.PyAddNewVirtualEnvFromFilePanel -import com.intellij.python.sdk.ui.icons.PythonSdkUIIcons import com.intellij.ui.IdeBorderFactory import com.intellij.ui.components.JBLabel import com.intellij.util.ui.JBUI -import com.jetbrains.python.PyToolUIInfo +import com.jetbrains.python.ToolId import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.packaging.PyPackageUtil import com.jetbrains.python.packaging.management.PythonPackageManager @@ -49,10 +48,9 @@ private val LOGGER = fileLogger() @ApiStatus.Internal class PyRequirementsTxtOrSetupPySdkConfiguration : PyProjectSdkConfigurationExtension { - override val toolInfo: PyToolUIInfo = PyToolUIInfo("venv", PythonSdkUIIcons.Tools.Pip) + override val toolId: ToolId = ToolId("PyRequirements") // This is nonsense, but will be dropped soon override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkManageableEnv(module) }, ) { { needsConfirmation -> createAndAddSdk(module, if (needsConfirmation) Source.CONFIGURATOR else Source.INSPECTION) } } diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyUvSdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyUvSdkConfiguration.kt index 5641771aa6ca..61e983d839b3 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyUvSdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyUvSdkConfiguration.kt @@ -41,15 +41,14 @@ class PyUvSdkConfiguration : PyProjectTomlConfigurationExtension { private val existingSdks by lazy { PythonSdkUtil.getAllSdks() } private val context = UserDataHolderBase() - override val toolInfo: PyToolUIInfo = UV_UI_INFO override val toolId: ToolId = UV_TOOL_ID override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, true) } + { checkExistence -> checkManageableEnv(module, checkExistence, true) } ) { envExists -> { createUv(module, envExists) } } override suspend fun createSdkWithoutPyProjectTomlChecks(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkExistence -> checkManageableEnv(module, checkExistence, false) } + { checkExistence -> checkManageableEnv(module, checkExistence, false) } ) { envExists -> { createUv(module, envExists) } } override fun asPyProjectTomlSdkConfigurationExtension(): PyProjectTomlConfigurationExtension = this diff --git a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyVenvSdkConfiguration.kt b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyVenvSdkConfiguration.kt index b216f6c1b8e5..48a3805988ab 100644 --- a/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyVenvSdkConfiguration.kt +++ b/python/ide/impl/src/com/intellij/pycharm/community/ide/impl/configuration/PyVenvSdkConfiguration.kt @@ -9,6 +9,7 @@ import com.intellij.pycharm.community.ide.impl.PyCharmCommunityCustomizationBund import com.intellij.pycharm.community.ide.impl.findEnvOrNull import com.jetbrains.python.PyBundle import com.jetbrains.python.PyToolUIInfo +import com.jetbrains.python.ToolId import com.jetbrains.python.errorProcessing.MessageError import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.sdk.* @@ -26,10 +27,10 @@ class PyVenvSdkConfiguration : PyProjectSdkConfigurationExtension { private val existingSdks by lazy { PythonSdkUtil.getAllSdks() } private val context = UserDataHolderBase() - override val toolInfo: PyToolUIInfo = PyToolUIInfo("Virtualenv", null) + override val toolId: ToolId = ToolId("Venv") override suspend fun checkEnvironmentAndPrepareSdkCreator(module: Module): CreateSdkInfo? = prepareSdkCreator( - toolInfo, { checkManageableEnv(module) } + { checkManageableEnv(module) } ) { { setupVenv(module) } } override fun asPyProjectTomlSdkConfigurationExtension(): PyProjectTomlConfigurationExtension? = null diff --git a/python/python-sdk-ui/src/com/intellij/python/sdk/ui/evolution/ui/autoconfiguration.kt b/python/python-sdk-ui/src/com/intellij/python/sdk/ui/evolution/ui/autoconfiguration.kt index 15a6c48a6904..3756003c1c95 100644 --- a/python/python-sdk-ui/src/com/intellij/python/sdk/ui/evolution/ui/autoconfiguration.kt +++ b/python/python-sdk-ui/src/com/intellij/python/sdk/ui/evolution/ui/autoconfiguration.kt @@ -42,7 +42,7 @@ private class AutoconfigSelectSdkProvider() : EvoSelectSdkProvider { val section = EvoTreeSection( label = null, elements = createSdkInfoWithTools.mapIndexed { idx, createSdkInfoWithTool -> - EvoTreeLeafElement(RunConfiguratorAction(createSdkInfoWithTool.intentionName, idx)) + EvoTreeLeafElement(RunConfiguratorAction(createSdkInfoWithTool.createSdkInfo.intentionName, idx)) } ) diff --git a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/CreateSdkInfo.kt b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/CreateSdkInfo.kt index 776571fdbd4f..2b6a6f59c975 100644 --- a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/CreateSdkInfo.kt +++ b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/CreateSdkInfo.kt @@ -2,7 +2,6 @@ package com.jetbrains.python.sdk.configuration import com.intellij.codeInspection.util.IntentionName import com.intellij.openapi.projectRoots.Sdk -import com.jetbrains.python.PyToolUIInfo import com.jetbrains.python.PythonInfo import com.jetbrains.python.errorProcessing.PyResult import org.jetbrains.annotations.ApiStatus @@ -16,7 +15,6 @@ typealias EnvExists = Boolean sealed interface CreateSdkInfo : Comparable { @get:IntentionName val intentionName: String - val toolInfo: PyToolUIInfo val sdkCreator: suspend (NeedsConfirmation) -> PyResult /** @@ -40,13 +38,11 @@ sealed interface CreateSdkInfo : Comparable { data class ExistingEnv( val pythonInfo: PythonInfo, override val intentionName: String, - override val toolInfo: PyToolUIInfo, override val sdkCreator: suspend (NeedsConfirmation) -> PyResult, ) : CreateSdkInfo data class WillCreateEnv( override val intentionName: String, - override val toolInfo: PyToolUIInfo, override val sdkCreator: suspend (NeedsConfirmation) -> PyResult, ) : CreateSdkInfo } @@ -61,7 +57,6 @@ sealed interface EnvCheckerResult { @ApiStatus.Internal // TODO: Make internal after we drop WSL sdk configurator suspend fun prepareSdkCreator( - toolInfo: PyToolUIInfo, envChecker: suspend (CheckExistence) -> EnvCheckerResult, sdkCreator: (EnvExists) -> (suspend (NeedsConfirmation) -> PyResult), ): CreateSdkInfo? { @@ -70,13 +65,12 @@ suspend fun prepareSdkCreator( is EnvCheckerResult.EnvFound -> CreateSdkInfo.ExistingEnv( res.pythonInfo, res.intentionName, - toolInfo, sdkCreator(true) ) is EnvCheckerResult.EnvNotFound -> { res = envChecker(false) when (res) { - is EnvCheckerResult.EnvNotFound -> CreateSdkInfo.WillCreateEnv(res.intentionName, toolInfo, sdkCreator(false)) + is EnvCheckerResult.EnvNotFound -> CreateSdkInfo.WillCreateEnv(res.intentionName, sdkCreator(false)) is EnvCheckerResult.EnvFound -> throw AssertionError("Env shouldn't exist if we didn't check for it") is EnvCheckerResult.CannotConfigure -> null } diff --git a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfigurationExtension.kt b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfigurationExtension.kt index ae7294a08960..4f2646df20c3 100644 --- a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfigurationExtension.kt +++ b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfigurationExtension.kt @@ -3,7 +3,7 @@ package com.jetbrains.python.sdk.configuration import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.module.Module -import com.jetbrains.python.PyToolUIInfo +import com.jetbrains.python.ToolId import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.CheckReturnValue @@ -24,11 +24,12 @@ interface PyProjectSdkConfigurationExtension { * We return all configurators in a sorted order. The order is determined by extensions order, but existing environments have a * higher priority. That means we first have all existing envs, and only after SDK creators that extensions can manage. */ - suspend fun findAllSortedForModule(module: Module): List = EP_NAME.extensionsIfPointIsRegistered - .mapNotNull { e -> e.checkEnvironmentAndPrepareSdkCreator(module) }.sorted() + suspend fun findAllSortedForModule(module: Module): List = EP_NAME.extensionsIfPointIsRegistered + .mapNotNull { e -> e.checkEnvironmentAndPrepareSdkCreator(module)?.let { CreateSdkInfoWithTool(it, e.toolId) } } + .sortedBy { it.createSdkInfo } } - val toolInfo: PyToolUIInfo + val toolId: ToolId /** * Discovers whether this extension can provide a Python SDK for the given module and prepares a creator for it. @@ -65,3 +66,8 @@ interface PyProjectSdkConfigurationExtension { */ fun asPyProjectTomlSdkConfigurationExtension(): PyProjectTomlConfigurationExtension? } + +/** + * [createSdkInfo] with [toolId] that created it + */ +data class CreateSdkInfoWithTool(val createSdkInfo: CreateSdkInfo, val toolId: ToolId) diff --git a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectTomlConfigurationExtension.kt b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectTomlConfigurationExtension.kt index 3ffd5ad6c29e..3f30ea0081c4 100644 --- a/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectTomlConfigurationExtension.kt +++ b/python/python-sdk/src/com/jetbrains/python/sdk/configuration/PyProjectTomlConfigurationExtension.kt @@ -6,7 +6,6 @@ import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal interface PyProjectTomlConfigurationExtension : PyProjectSdkConfigurationExtension { - val toolId: ToolId suspend fun createSdkWithoutPyProjectTomlChecks(module: Module): CreateSdkInfo? } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java b/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java index 38ad254f80e2..ce6717da0892 100644 --- a/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyInterpreterInspection.java @@ -39,7 +39,7 @@ import com.jetbrains.python.sdk.PySdkExtKt; import com.jetbrains.python.sdk.PySdkPopupFactory; import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.conda.PyCondaSdkCustomizer; -import com.jetbrains.python.sdk.configuration.CreateSdkInfo; +import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool; import com.jetbrains.python.sdk.configuration.PyProjectSdkConfiguration; import com.jetbrains.python.sdk.configuration.PyProjectSdkConfigurationExtension; import com.jetbrains.python.sdk.legacy.PythonSdkUtil; @@ -131,7 +131,7 @@ public final class PyInterpreterInspection extends PyInspection { final UserDataHolderBase context = new UserDataHolderBase(); - final List createSdkInfos = findAllSortedForModuleForJvm(module); + final List createSdkInfos = findAllSortedForModuleForJvm(module); if (!createSdkInfos.isEmpty()) { return new UseProvidedInterpreterFix(module, createSdkInfos.getFirst()); } @@ -170,7 +170,7 @@ public final class PyInterpreterInspection extends PyInspection { PyProjectSdkConfigurationExtension configurator = PyCondaSdkCustomizer.Companion.getInstance().getFallbackConfigurator(); if (configurator != null) { - final CreateSdkInfo fallbackCreateSdkInfo = + var fallbackCreateSdkInfo = PyCondaSdkCustomizer.Companion.checkEnvironmentAndPrepareSdkCreatorBlocking(configurator, module); if (fallbackCreateSdkInfo != null) { return new UseProvidedInterpreterFix(module, fallbackCreateSdkInfo); @@ -323,10 +323,10 @@ public final class PyInterpreterInspection extends PyInspection { private final @NotNull Module myModule; - private final @NotNull CreateSdkInfo myCreateSdkInfo; + private final @NotNull CreateSdkInfoWithTool myCreateSdkInfo; private UseProvidedInterpreterFix(@NotNull Module module, - @NotNull CreateSdkInfo createSdkInfo) { + @NotNull CreateSdkInfoWithTool createSdkInfo) { myModule = module; myCreateSdkInfo = createSdkInfo; } @@ -338,7 +338,7 @@ public final class PyInterpreterInspection extends PyInspection { @Override public @IntentionName @NotNull String getName() { - return myCreateSdkInfo.getIntentionName(); + return myCreateSdkInfo.getCreateSdkInfo().getIntentionName(); } @Override diff --git a/python/src/com/jetbrains/python/inspections/PyInterpreterInspectionEx.kt b/python/src/com/jetbrains/python/inspections/PyInterpreterInspectionEx.kt index b3bc445a5a82..08d1dc8f4794 100644 --- a/python/src/com/jetbrains/python/inspections/PyInterpreterInspectionEx.kt +++ b/python/src/com/jetbrains/python/inspections/PyInterpreterInspectionEx.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.project.Project import com.intellij.python.sdkConfigurator.common.detectSdkForModulesIn import com.intellij.python.sdkConfigurator.common.enableSDKAutoConfigurator import com.intellij.util.concurrency.annotations.RequiresBackgroundThread -import com.jetbrains.python.sdk.configuration.CreateSdkInfo +import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool import com.jetbrains.python.sdk.configuration.PyProjectSdkConfigurationExtension import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -37,6 +37,6 @@ private class MyService(val scope: CoroutineScope) */ @ApiStatus.Internal @RequiresBackgroundThread -internal fun findAllSortedForModuleForJvm(module: Module): List = runBlockingMaybeCancellable { +internal fun findAllSortedForModuleForJvm(module: Module): List = runBlockingMaybeCancellable { PyProjectSdkConfigurationExtension.findAllSortedForModule(module) } diff --git a/python/src/com/jetbrains/python/sdk/conda/PyCondaSdkCustomizer.kt b/python/src/com/jetbrains/python/sdk/conda/PyCondaSdkCustomizer.kt index a23d560d79ff..a51d88ea2ecc 100644 --- a/python/src/com/jetbrains/python/sdk/conda/PyCondaSdkCustomizer.kt +++ b/python/src/com/jetbrains/python/sdk/conda/PyCondaSdkCustomizer.kt @@ -6,6 +6,7 @@ import com.intellij.openapi.module.Module import com.intellij.openapi.progress.runBlockingMaybeCancellable import com.intellij.util.concurrency.annotations.RequiresBackgroundThread import com.jetbrains.python.sdk.configuration.CreateSdkInfo +import com.jetbrains.python.sdk.configuration.CreateSdkInfoWithTool import com.jetbrains.python.sdk.configuration.PyProjectSdkConfigurationExtension import org.jetbrains.annotations.ApiStatus @@ -35,9 +36,9 @@ interface PyCondaSdkCustomizer { get() = EP_NAME.extensionList.first() @RequiresBackgroundThread - fun checkEnvironmentAndPrepareSdkCreatorBlocking(extension: PyProjectSdkConfigurationExtension, module: Module): CreateSdkInfo? = + fun checkEnvironmentAndPrepareSdkCreatorBlocking(extension: PyProjectSdkConfigurationExtension, module: Module): CreateSdkInfoWithTool? = runBlockingMaybeCancellable { - extension.checkEnvironmentAndPrepareSdkCreator(module) + extension.checkEnvironmentAndPrepareSdkCreator(module)?.let { CreateSdkInfoWithTool(it, extension.toolId) } } } } diff --git a/python/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfiguration.kt b/python/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfiguration.kt index 00e77800c83a..e9055f4b36bd 100644 --- a/python/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfiguration.kt +++ b/python/src/com/jetbrains/python/sdk/configuration/PyProjectSdkConfiguration.kt @@ -18,7 +18,6 @@ import com.intellij.openapi.wm.ex.WelcomeScreenProjectProvider import com.intellij.platform.ide.progress.withBackgroundProgress import com.jetbrains.python.PyBundle import com.jetbrains.python.PythonPluginDisposable -import com.jetbrains.python.errorProcessing.PyResult import com.jetbrains.python.errorProcessing.emit import com.jetbrains.python.packaging.utils.PyPackageCoroutine import com.jetbrains.python.sdk.PySdkPopupFactory @@ -33,23 +32,23 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext object PyProjectSdkConfiguration { - fun configureSdkUsingCreateSdkInfo(module: Module, createSdkInfo: CreateSdkInfo) { - val lifetime = suppressTipAndInspectionsFor(module, createSdkInfo.toolInfo.toolName) + fun configureSdkUsingCreateSdkInfo(module: Module, createSdkInfoWithTool: CreateSdkInfoWithTool) { + val lifetime = suppressTipAndInspectionsFor(module, createSdkInfoWithTool.toolId.id) val project = module.project PyPackageCoroutine.launch(project) { - withBackgroundProgress(project, createSdkInfo.intentionName, false) { - lifetime.use { setSdkUsingCreateSdkInfo(module, createSdkInfo, false) } + withBackgroundProgress(project, createSdkInfoWithTool.createSdkInfo.intentionName, false) { + lifetime.use { setSdkUsingCreateSdkInfo(module, createSdkInfoWithTool, false) } } } } suspend fun setSdkUsingCreateSdkInfo( - module: Module, createSdkInfo: CreateSdkInfo, needsConfirmation: NeedsConfirmation, + module: Module, createSdkInfoWithTool: CreateSdkInfoWithTool, needsConfirmation: NeedsConfirmation, ): Boolean = withContext(Dispatchers.Default) { - thisLogger().debug("Configuring sdk using ${createSdkInfo.toolInfo.toolName}") + thisLogger().debug("Configuring sdk using ${createSdkInfoWithTool.toolId}") - val sdk = createSdkInfo.sdkCreator(needsConfirmation).getOr { + val sdk = createSdkInfoWithTool.createSdkInfo.sdkCreator(needsConfirmation).getOr { ShowingMessageErrorSync.emit(it.error, module.project) return@withContext true } ?: return@withContext false