mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-23 07:39:39 +07:00
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:
committed by
intellij-monorepo-bot
parent
088eb4ef09
commit
107201d413
@@ -1,21 +1,27 @@
|
||||
// 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.execService.python.advancedApi
|
||||
|
||||
import com.intellij.python.community.execService.python.advancedApi.ExecutablePython.Companion.vanillaExecutablePython
|
||||
import com.jetbrains.python.PythonBinary
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* Something that can execute python code (vanilla cpython, conda).
|
||||
* `[binary] [args]` <python-args-go-here> (i.e `-m foo.py`).
|
||||
* For [VanillaExecutablePython] it is `python` without arguments, but for conda it might be `conda run` etc
|
||||
* [env] are added to the environment
|
||||
* For [vanillaExecutablePython] it is `python` without arguments, but for conda it might be `conda run` etc
|
||||
*/
|
||||
interface ExecutablePython {
|
||||
val binary: Path
|
||||
val args: List<String>
|
||||
data class ExecutablePython(
|
||||
val binary: Path,
|
||||
val args: List<String>,
|
||||
val env: Map<String, String>,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
class VanillaExecutablePython(override val binary: PythonBinary) : ExecutablePython {
|
||||
override val args: List<String> = emptyList()
|
||||
}
|
||||
/**
|
||||
* Plain python that doesn't have args nor envs
|
||||
*/
|
||||
fun vanillaExecutablePython(binary: PythonBinary): ExecutablePython =
|
||||
ExecutablePython(binary, emptyList(), emptyMap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ suspend fun <T> ExecService.executePythonAdvanced(
|
||||
executeAdvanced(python.binary, {
|
||||
addArgs(*python.args.toTypedArray())
|
||||
argsBuilder()
|
||||
}, options, processInteractiveHandler)
|
||||
// TODO: Merge PATH
|
||||
}, options.copy(env = options.env + python.env), processInteractiveHandler)
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.intellij.python.community.execService.ExecOptions
|
||||
import com.intellij.python.community.execService.ExecService
|
||||
import com.intellij.python.community.execService.PyProcessListener
|
||||
import com.intellij.python.community.execService.ZeroCodeStdoutTransformer
|
||||
import com.intellij.python.community.execService.python.advancedApi.ExecutablePython.Companion.VanillaExecutablePython
|
||||
import com.intellij.python.community.execService.python.advancedApi.ExecutablePython
|
||||
import com.intellij.python.community.execService.python.advancedApi.executeHelperAdvanced
|
||||
import com.intellij.python.community.execService.python.advancedApi.validatePythonAndGetVersion
|
||||
import com.jetbrains.python.PythonBinary
|
||||
@@ -25,8 +25,7 @@ suspend fun ExecService.executeHelper(
|
||||
options: ExecOptions = ExecOptions(),
|
||||
procListener: PyProcessListener? = null,
|
||||
): PyExecResult<String> =
|
||||
executeHelperAdvanced(VanillaExecutablePython(python), helper, args, options, procListener, ZeroCodeStdoutTransformer)
|
||||
|
||||
executeHelperAdvanced(ExecutablePython.vanillaExecutablePython(python), helper, args, options, procListener, ZeroCodeStdoutTransformer)
|
||||
|
||||
/**
|
||||
* Ensures that this python is executable and returns its version. Error if python is broken.
|
||||
@@ -36,6 +35,6 @@ suspend fun ExecService.executeHelper(
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinary): PyResult<LanguageLevel> =
|
||||
validatePythonAndGetVersion(VanillaExecutablePython(python))
|
||||
validatePythonAndGetVersion(ExecutablePython.vanillaExecutablePython(python))
|
||||
|
||||
suspend fun PythonBinary.validatePythonAndGetVersion(): PyResult<LanguageLevel> = ExecService().validatePythonAndGetVersion(this)
|
||||
Reference in New Issue
Block a user