diff --git a/python/src/com/jetbrains/python/sdk/add/v2/models.kt b/python/src/com/jetbrains/python/sdk/add/v2/models.kt index 6702e671fad2..e288933a1b79 100644 --- a/python/src/com/jetbrains/python/sdk/add/v2/models.kt +++ b/python/src/com/jetbrains/python/sdk/add/v2/models.kt @@ -4,7 +4,6 @@ package com.jetbrains.python.sdk.add.v2 import com.intellij.execution.target.TargetEnvironmentConfiguration import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.application.EDT -import com.intellij.openapi.application.ModalityState import com.intellij.openapi.diagnostic.getOrLogException import com.intellij.openapi.fileChooser.FileChooser import com.intellij.openapi.observable.properties.ObservableMutableProperty @@ -26,8 +25,11 @@ import com.jetbrains.python.sdk.flavors.conda.PyCondaEnvIdentity import com.jetbrains.python.sdk.pipenv.pipEnvPath import com.jetbrains.python.sdk.poetry.poetryPath import com.jetbrains.python.util.ErrorSink -import kotlinx.coroutines.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.* +import kotlinx.coroutines.plus +import kotlinx.coroutines.withContext import java.nio.file.Path import kotlin.io.path.pathString @@ -61,6 +63,7 @@ abstract class PythonAddInterpreterModel(params: PyInterpreterModelParams) { .stateIn(scope + uiContext, started = SharingStarted.Eagerly, initialValue = emptyList()) val baseInterpreters: StateFlow> = allInterpreters + .map { it.filter { it.isBasePython() } } .mapLatest { it.filter { it !is ExistingSelectableInterpreter || it.isSystemWide } + installable } @@ -229,8 +232,15 @@ class PythonLocalAddInterpreterModel(params: PyInterpreterModelParams) } -// todo does it need target configuration sealed class PythonSelectableInterpreter { + /** + * Base python is some system python (not venv) which can be used as a base for venv. + * In terms of flavors we call it __not__ [PythonSdkFlavor.isPlatformIndependent] + */ + open suspend fun isBasePython(): Boolean = withContext(Dispatchers.IO) { + PythonSdkFlavor.tryDetectFlavorByLocalPath(homePath)?.isPlatformIndependent == false + } + abstract val homePath: String abstract val languageLevel: LanguageLevel override fun toString(): String = @@ -238,6 +248,10 @@ sealed class PythonSelectableInterpreter { } class ExistingSelectableInterpreter(val sdk: Sdk, override val languageLevel: LanguageLevel, val isSystemWide: Boolean) : PythonSelectableInterpreter() { + override suspend fun isBasePython(): Boolean = withContext(Dispatchers.IO) { + !sdk.sdkFlavor.isPlatformIndependent + } + override val homePath = sdk.homePath!! // todo is it safe } @@ -246,6 +260,7 @@ class DetectedSelectableInterpreter(override val homePath: String, override val class ManuallyAddedSelectableInterpreter(override val homePath: String, override val languageLevel: LanguageLevel) : PythonSelectableInterpreter() class InstallableSelectableInterpreter(val sdk: PySdkToInstall) : PythonSelectableInterpreter() { + override suspend fun isBasePython(): Boolean = true override val homePath: String = "" override val languageLevel = PySdkUtil.getLanguageLevelForSdk(sdk) }