From 4a4b432d920368990f0eca09a351935f2e753824 Mon Sep 17 00:00:00 2001 From: Andrey Vokin Date: Wed, 7 Apr 2021 12:21:13 +0200 Subject: [PATCH] DS-1519: preset guessed default conda environment into conda environment combobox DS-1519 Make "Launch DataSpell" button disabled and provide corresponding messages when no valid environment configuration selected on environment tab GitOrigin-RevId: 6027f6034533ca5716c3d5bcc4f599d75efa8f4a --- .../python/packaging/PyCondaPackageService.java | 9 +++++++-- python/src/com/jetbrains/python/sdk/PySdkExt.kt | 15 +++++++++++++++ .../com/jetbrains/python/sdk/add/PyAddSdkPanel.kt | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/python/python-sdk/src/com/jetbrains/python/packaging/PyCondaPackageService.java b/python/python-sdk/src/com/jetbrains/python/packaging/PyCondaPackageService.java index 030deeabe4d6..3424fd4ffb52 100644 --- a/python/python-sdk/src/com/jetbrains/python/packaging/PyCondaPackageService.java +++ b/python/python-sdk/src/com/jetbrains/python/packaging/PyCondaPackageService.java @@ -80,13 +80,18 @@ public class PyCondaPackageService implements PersistentStateComponent): List { fun detectCondaEnvs(module: Module?, existingSdks: List, context: UserDataHolder): List = filterSuggestedPaths(CondaEnvSdkFlavor.getInstance().suggestHomePaths(module, context), existingSdks, module, true) +fun guessCondaBaseEnvironment(condaPath: String): Sdk? { + if (!condaPath.endsWith(File.separatorChar + getCondaName())) { + return null + } + + val interpreterPath = condaPath.replaceAfterLast(File.separatorChar, getPythonName()) + val condaVirtualFile = VfsUtil.findFileByIoFile(File(interpreterPath), false) + if (condaVirtualFile != null && condaVirtualFile.exists()) { + return PyDetectedSdk(condaVirtualFile.path) + } + return null +} + fun filterAssociatedSdks(module: Module, existingSdks: List): List { return existingSdks.filter { it.sdkType is PythonSdkType && it.isAssociatedWithModule(module) } } diff --git a/python/src/com/jetbrains/python/sdk/add/PyAddSdkPanel.kt b/python/src/com/jetbrains/python/sdk/add/PyAddSdkPanel.kt index 65152cdf086d..73caacb33c46 100644 --- a/python/src/com/jetbrains/python/sdk/add/PyAddSdkPanel.kt +++ b/python/src/com/jetbrains/python/sdk/add/PyAddSdkPanel.kt @@ -141,6 +141,7 @@ fun addInterpretersAsync(sdkComboBox: PySdkPathChoosingComboBox, finally { executor.execute { sdkComboBox.setBusy(false) + sdkComboBox.childComponent.removeAllItems() sdks.forEach(sdkComboBox.childComponent::addItem) onAdded() }