Python: refactoring before interpreters service.

Extract various classes to the shared modules, `ExecutablePython` now has `env` map as it can be used by conda.

GitOrigin-RevId: eb45ea29f49132fa4f91c979f71453e6a2ade344
This commit is contained in:
Ilya.Kazakevich
2025-06-08 04:14:00 +00:00
committed by intellij-monorepo-bot
parent 088eb4ef09
commit 107201d413
16 changed files with 63 additions and 38 deletions
@@ -7,7 +7,6 @@ import com.intellij.platform.eel.provider.getEelDescriptor
import com.intellij.python.community.execService.python.validatePythonAndGetVersion
import com.intellij.python.community.services.internal.impl.VanillaPythonWithLanguageLevelImpl.Companion.concurrentLimit
import com.intellij.python.community.services.internal.impl.VanillaPythonWithLanguageLevelImpl.Companion.createByPythonBinary
import com.intellij.python.community.services.shared.PythonWithLanguageLevel
import com.intellij.python.community.services.shared.VanillaPythonWithLanguageLevel
import com.jetbrains.python.PythonBinary
import com.jetbrains.python.Result
@@ -83,6 +82,4 @@ class VanillaPythonWithLanguageLevelImpl internal constructor(
return "$pythonString ($languageLevel)"
}
// Backward: first python is the highest
override fun compareTo(other: PythonWithLanguageLevel): Int = languageLevel.compareTo(other.languageLevel) * -1
}
@@ -3,12 +3,11 @@ package com.intellij.python.community.services.shared
import com.intellij.python.community.execService.python.advancedApi.ExecutablePython
import com.jetbrains.python.psi.LanguageLevel
import org.jetbrains.annotations.Nls
/**
* Python (vanilla, conda, whatever) with known language level.
*/
interface PythonWithLanguageLevel : Comparable<PythonWithLanguageLevel> {
interface PythonWithLanguageLevel : Comparable<PythonWithLanguageLevel>, PythonWithName {
val languageLevel: LanguageLevel
/**
@@ -16,9 +15,8 @@ interface PythonWithLanguageLevel : Comparable<PythonWithLanguageLevel> {
*/
val asExecutablePython: ExecutablePython
/**
* Name can be displayed to the end user
*/
suspend fun getReadableName(): @Nls String
// Backward: first python is the highest
override fun compareTo(other: PythonWithLanguageLevel): Int = languageLevel.compareTo(other.languageLevel) * -1
}
@@ -0,0 +1,11 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.services.shared
import org.jetbrains.annotations.Nls
interface PythonWithName {
/**
* Name can be displayed to the end user
*/
suspend fun getReadableName(): @Nls String
}
@@ -0,0 +1,6 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.services.shared
interface PythonWithUi : PythonWithLanguageLevel {
val ui: UICustomization?
}
@@ -0,0 +1,13 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.python.community.services.shared
import org.jetbrains.annotations.Nls
import javax.swing.Icon
data class UICustomization(
/**
* i.e: "UV" for pythons found by UV
*/
val title: @Nls String,
val icon: Icon? = null,
)
@@ -10,6 +10,6 @@ import com.jetbrains.python.PythonBinary
*/
interface VanillaPythonWithLanguageLevel : PythonWithLanguageLevel {
val pythonBinary: PythonBinary
override val asExecutablePython: ExecutablePython get() = ExecutablePython.Companion.VanillaExecutablePython(pythonBinary)
override val asExecutablePython: ExecutablePython get() = ExecutablePython.vanillaExecutablePython(pythonBinary)
}
@@ -6,6 +6,8 @@ import com.intellij.openapi.components.service
import com.intellij.platform.eel.EelApi
import com.intellij.platform.eel.provider.localEel
import com.intellij.python.community.impl.venv.createVenv
import com.intellij.python.community.services.shared.PythonWithUi
import com.intellij.python.community.services.shared.UICustomization
import com.intellij.python.community.services.shared.VanillaPythonWithLanguageLevel
import com.jetbrains.python.PythonBinary
import com.jetbrains.python.Result
@@ -15,8 +17,6 @@ import com.jetbrains.python.venvReader.VirtualEnvReader
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.ApiStatus.Internal
import org.jetbrains.annotations.CheckReturnValue
import org.jetbrains.annotations.Nls
import javax.swing.Icon
/**
* Service to register and obtain [SystemPython]s
@@ -55,7 +55,7 @@ fun SystemPythonService(): SystemPythonService = ApplicationManager.getApplicati
*
* Instances could be obtained with [SystemPythonService]
*/
class SystemPython internal constructor(private val impl: VanillaPythonWithLanguageLevel, val ui: UICustomization?) : VanillaPythonWithLanguageLevel by impl {
class SystemPython internal constructor(private val impl: VanillaPythonWithLanguageLevel, override val ui: UICustomization?) : VanillaPythonWithLanguageLevel by impl, PythonWithUi {
override fun equals(other: Any?): Boolean {
if (this === other) return true
@@ -94,14 +94,6 @@ sealed interface PythonInstallerService {
suspend fun installLatestPython(): Result<Unit, String>
}
data class UICustomization(
/**
* i.e: "UV" for pythons found by UV
*/
val title: @Nls String,
val icon: Icon? = null,
)
/**
* See [createVenv]
*/
@@ -3,6 +3,7 @@ package com.intellij.python.community.services.systemPython
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.platform.eel.EelApi
import com.intellij.python.community.services.shared.UICustomization
import com.intellij.python.community.services.systemPython.SystemPythonProvider.Companion.EP
import com.jetbrains.python.PythonBinary
import com.jetbrains.python.errorProcessing.PyResult
@@ -12,6 +12,7 @@ import com.intellij.platform.eel.provider.getEelDescriptor
import com.intellij.platform.eel.provider.localEel
import com.intellij.python.community.impl.installer.PySdkToInstallManager
import com.intellij.python.community.services.internal.impl.VanillaPythonWithLanguageLevelImpl
import com.intellij.python.community.services.shared.UICustomization
import com.intellij.python.community.services.systemPython.SystemPythonServiceImpl.MyServiceState
import com.intellij.python.community.services.systemPython.impl.Cache
import com.intellij.python.community.services.systemPython.impl.CoreSystemPythonProvider
@@ -4,9 +4,9 @@ package com.intellij.python.junit5Tests.env.systemPython.impl
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.python.community.impl.venv.createVenv
import com.intellij.python.community.services.shared.UICustomization
import com.intellij.python.community.services.systemPython.SystemPythonProvider
import com.intellij.python.community.services.systemPython.SystemPythonService
import com.intellij.python.community.services.systemPython.UICustomization
import com.intellij.python.junit5Tests.framework.env.PyEnvTestCase
import com.intellij.python.junit5Tests.framework.env.PythonBinaryPath
import com.intellij.testFramework.common.timeoutRunBlocking