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
This commit is contained in:
Andrey Vokin
2021-04-07 10:30:47 +00:00
committed by intellij-monorepo-bot
parent 1fd57c09c0
commit 4a4b432d92
3 changed files with 23 additions and 2 deletions
@@ -80,13 +80,18 @@ public class PyCondaPackageService implements PersistentStateComponent<PyCondaPa
}
@NotNull
private static String getPythonName() {
public static String getPythonName() {
return SystemInfo.isWindows ? "python.exe" : "python";
}
@NotNull
public static String getCondaName() {
return SystemInfo.isWindows ? "conda.exe" : "conda";
}
@Nullable
public static String getSystemCondaExecutable() {
final String condaName = SystemInfo.isWindows ? "conda.exe" : "conda";
final String condaName = getCondaName();
final File condaInPath = PathEnvironmentVariableUtil.findInPath(condaName);
if (condaInPath != null) return condaInPath.getPath();
return getCondaExecutableByName(condaName);
@@ -43,6 +43,8 @@ import com.intellij.util.PathUtil
import com.intellij.util.ThreeState
import com.intellij.webcore.packaging.PackagesNotificationPanel
import com.jetbrains.python.PyBundle
import com.jetbrains.python.packaging.PyCondaPackageService.getCondaName
import com.jetbrains.python.packaging.PyCondaPackageService.getPythonName
import com.jetbrains.python.packaging.ui.PyPackageManagementService
import com.jetbrains.python.psi.LanguageLevel
import com.jetbrains.python.sdk.flavors.CondaEnvSdkFlavor
@@ -113,6 +115,19 @@ fun filterSharedCondaEnvs(module: Module?, existingSdks: List<Sdk>): List<Sdk> {
fun detectCondaEnvs(module: Module?, existingSdks: List<Sdk>, context: UserDataHolder): List<PyDetectedSdk> =
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<Sdk>): List<Sdk> {
return existingSdks.filter { it.sdkType is PythonSdkType && it.isAssociatedWithModule(module) }
}
@@ -141,6 +141,7 @@ fun addInterpretersAsync(sdkComboBox: PySdkPathChoosingComboBox,
finally {
executor.execute {
sdkComboBox.setBusy(false)
sdkComboBox.childComponent.removeAllItems()
sdks.forEach(sdkComboBox.childComponent::addItem)
onAdded()
}