Files
openide/python/python-exec-service/execService.python/src/api.kt
Ilya.Kazakevich 0cf893efdf Python: support getting version for python on target.
See test for usage example

GitOrigin-RevId: aa65f15d294585040c3cdadc2ef3057c85136a19
2025-08-27 22:56:52 +00:00

51 lines
2.4 KiB
Kotlin

// 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.*
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.intellij.python.community.helpersLocator.PythonHelpersLocator
import com.jetbrains.python.PythonBinary
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`
*/
suspend fun ExecService.executeHelper(
python: PythonBinary,
helper: HelperName,
args: List<String> = emptyList(),
options: ExecOptions = ExecOptions(),
procListener: PyProcessListener? = null,
): PyResult<String> =
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.
*
* 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
*/
suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinaryOnEelOrTarget): PyResult<LanguageLevel> =
validatePythonAndGetVersion(ExecutablePython.vanillaExecutablePython(python))
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()
/**
* Adds helper by copying it to the remote system (if needed)
*/
fun Args.addHelper(helper: HelperName): Args =
addLocalFile(PythonHelpersLocator.findPathInHelpers(helper))