// 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 = emptyList(), options: ExecOptions = ExecOptions(), procListener: PyProcessListener? = null, ): PyResult = 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 = validatePythonAndGetVersion(ExecutablePython.vanillaExecutablePython(python)) suspend fun PythonBinaryOnEelOrTarget.validatePythonAndGetVersion(): PyResult = ExecService().validatePythonAndGetVersion(this) suspend fun ExecService.validatePythonAndGetVersion(python: PythonBinary): PyResult = validatePythonAndGetVersion(python.asBinToExec()) suspend fun PythonBinary.validatePythonAndGetVersion(): PyResult = asBinToExec().validatePythonAndGetVersion() /** * Adds helper by copying it to the remote system (if needed) */ fun Args.addHelper(helper: HelperName): Args = addLocalFile(PythonHelpersLocator.findPathInHelpers(helper))