mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-05 14:11:26 +07:00
Python: support getting version for python on target.
See test for usage example GitOrigin-RevId: aa65f15d294585040c3cdadc2ef3057c85136a19
This commit is contained in:
committed by
intellij-monorepo-bot
parent
99f702865c
commit
0cf893efdf
@@ -1,9 +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.execService.python.advancedApi
|
||||
|
||||
import com.intellij.python.community.execService.BinaryToExec
|
||||
import com.intellij.python.community.execService.asBinToExec
|
||||
import com.intellij.python.community.execService.python.PythonBinaryOnEelOrTarget
|
||||
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).
|
||||
@@ -12,7 +14,7 @@ import java.nio.file.Path
|
||||
* For [vanillaExecutablePython] it is `python` without arguments, but for conda it might be `conda run` etc
|
||||
*/
|
||||
data class ExecutablePython(
|
||||
val binary: Path,
|
||||
val binary: BinaryToExec,
|
||||
val args: List<String>,
|
||||
val env: Map<String, String>,
|
||||
) {
|
||||
@@ -21,7 +23,10 @@ data class ExecutablePython(
|
||||
/**
|
||||
* Plain python that doesn't have args nor envs
|
||||
*/
|
||||
fun vanillaExecutablePython(binary: PythonBinary): ExecutablePython =
|
||||
fun vanillaExecutablePython(binary: PythonBinaryOnEelOrTarget): ExecutablePython =
|
||||
ExecutablePython(binary, emptyList(), emptyMap())
|
||||
|
||||
fun vanillaExecutablePython(binary: PythonBinary): ExecutablePython = vanillaExecutablePython(binary.asBinToExec())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ suspend fun <T> ExecService.executePythonAdvanced(
|
||||
processInteractiveHandler: ProcessInteractiveHandler<T>,
|
||||
): PyResult<T> =
|
||||
executeAdvanced(
|
||||
binary = BinOnEel(python.binary),
|
||||
binary = python.binary,
|
||||
args = Args(*python.args.toTypedArray()).add(args),
|
||||
// TODO: Merge PATH
|
||||
options = options.copy(env = options.env + python.env), processInteractiveHandler)
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
// 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
|
||||
|
||||
import com.intellij.python.community.execService.Args
|
||||
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.*
|
||||
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
|
||||
@@ -15,6 +11,12 @@ import com.jetbrains.python.errorProcessing.PyResult
|
||||
import com.jetbrains.python.psi.LanguageLevel
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
* Python binary itself (i.e python.exe)
|
||||
*/
|
||||
typealias PythonBinaryOnEelOrTarget = BinaryToExec
|
||||
|
||||
|
||||
/**
|
||||
* Execute [helper] on [python]. For remote eels, [helper] is copied (but only one file!).
|
||||
* Returns `stdout`
|
||||
@@ -26,7 +28,7 @@ suspend fun ExecService.executeHelper(
|
||||
options: ExecOptions = ExecOptions(),
|
||||
procListener: PyProcessListener? = null,
|
||||
): PyResult<String> =
|
||||
executeHelperAdvanced(ExecutablePython.vanillaExecutablePython(python), helper, args, options, procListener, ZeroCodeStdoutTransformer)
|
||||
executeHelperAdvanced(ExecutablePython.vanillaExecutablePython(python.asBinToExec()), helper, args, options, procListener, ZeroCodeStdoutTransformer)
|
||||
|
||||
/**
|
||||
* Ensures that this python is executable and returns its version. Error if python is broken.
|
||||
@@ -34,11 +36,12 @@ suspend fun ExecService.executeHelper(
|
||||
* Some pythons might be broken: they may be executable, even return a version, but still fail to execute it.
|
||||
* As we need workable pythons, we validate it by executing
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinary): PyResult<LanguageLevel> =
|
||||
suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinaryOnEelOrTarget): PyResult<LanguageLevel> =
|
||||
validatePythonAndGetVersion(ExecutablePython.vanillaExecutablePython(python))
|
||||
|
||||
suspend fun PythonBinary.validatePythonAndGetVersion(): PyResult<LanguageLevel> = ExecService().validatePythonAndGetVersion(this)
|
||||
suspend fun PythonBinaryOnEelOrTarget.validatePythonAndGetVersion(): PyResult<LanguageLevel> = ExecService().validatePythonAndGetVersion(this)
|
||||
suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinary): PyResult<LanguageLevel> = validatePythonAndGetVersion(python.asBinToExec())
|
||||
suspend fun PythonBinary.validatePythonAndGetVersion(): PyResult<LanguageLevel> = asBinToExec().validatePythonAndGetVersion()
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,10 +5,7 @@ import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.platform.eel.provider.utils.EelProcessExecutionResult
|
||||
import com.intellij.platform.eel.provider.utils.stderrString
|
||||
import com.intellij.platform.eel.provider.utils.stdoutString
|
||||
import com.intellij.python.community.execService.Args
|
||||
import com.intellij.python.community.execService.ExecOptions
|
||||
import com.intellij.python.community.execService.ExecService
|
||||
import com.intellij.python.community.execService.ZeroCodeStdoutTransformer
|
||||
import com.intellij.python.community.execService.*
|
||||
import com.intellij.python.community.execService.impl.transformerToHandler
|
||||
import com.intellij.python.community.execService.python.advancedApi.ExecutablePython
|
||||
import com.intellij.python.community.execService.python.advancedApi.executePythonAdvanced
|
||||
@@ -46,4 +43,9 @@ internal suspend fun ExecService.validatePythonAndGetVersionImpl(python: Executa
|
||||
return@withContext Result.success(languageLevel)
|
||||
}
|
||||
|
||||
private val ExecutablePython.userReadableName: @NlsSafe String get() = (listOf(binary.pathString) + args).joinToString(" ")
|
||||
private val ExecutablePython.userReadableName: @NlsSafe String
|
||||
get() =
|
||||
(listOf(when (binary) {
|
||||
is BinOnEel -> binary.path.pathString
|
||||
is BinOnTarget -> binary
|
||||
}) + args).joinToString(" ")
|
||||
|
||||
Reference in New Issue
Block a user