System requirement validation and resolution for autorest.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Python interpreter detection and version validation with support for multiple Python executables and environment-specific configurations. Handles cross-platform Python detection including Windows py.exe launcher.
Resolves Python interpreter requirements with automatic detection of available Python executables and version validation.
/**
* Resolve Python interpreter requirement with cross-platform support
* @param requirement - Python requirement configuration
* @returns Resolution with Python command and version, or error details
*/
function resolvePythonRequirement(
requirement: SystemRequirement
): Promise<SystemRequirementResolution | SystemRequirementError>;Usage Example:
import { resolvePythonRequirement } from "@autorest/system-requirements";
// Basic Python requirement
const result = await resolvePythonRequirement({ version: ">=3.6" });
if ("error" in result) {
console.error("Python not found:", result.message);
} else {
console.log(`Python resolved: ${result.command}`);
// Example output: "Python resolved: python3"
}
// Using environment variable
const customResult = await resolvePythonRequirement({
version: ">=3.8",
environmentVariable: "AUTOREST_PYTHON_EXE"
});Updates Python command arrays with resolved Python paths for use in subprocess execution.
/**
* Patch Python command with resolved Python path
* @param command - Array with Python executable as first element
* @param requirement - Python requirement configuration
* @returns Modified command array with resolved Python path
* @throws Error if Python requirement cannot be satisfied
*/
function patchPythonPath(
command: PythonCommandLine,
requirement: SystemRequirement
): Promise<string[]>;Usage Example:
import { patchPythonPath } from "@autorest/system-requirements";
// Original command
const originalCommand: PythonCommandLine = ["python", "script.py", "--arg"];
// Patch with requirement
try {
const patchedCommand = await patchPythonPath(originalCommand, {
version: ">=3.6"
});
console.log("Patched command:", patchedCommand);
// Example output: ["python3", "script.py", "--arg"]
// or: ["C:\\Python39\\python.exe", "script.py", "--arg"]
} catch (error) {
console.error("Failed to resolve Python:", error.message);
}Legacy function for backward compatibility. Use patchPythonPath instead.
/**
* @deprecated Please use patchPythonPath(command, requirement) instead
* This method is kept for backward compatibility and will be removed in a future release
*/
function updatePythonPath(command: PythonCommandLine): Promise<string[]>;The Python resolver follows this detection order:
environmentVariable is specified in the requirement, or AUTOREST_PYTHON_EXE is setpy -3 commandpython3 executablepython executableEach candidate is tested by executing a version detection script to verify it's a working Python interpreter with the correct version.
/** Known Python executable names across platforms */
type KnownPythonExe = "python.exe" | "python3.exe" | "python" | "python3";
/** Command line array with Python executable as first element */
type PythonCommandLine = [KnownPythonExe, ...string[]];/** Python requirement identifier used in system requirement resolution */
const PythonRequirement = "python";Python version detection uses a small inline script:
import sys; print('.'.join(map(str, sys.version_info[:3])))This script outputs the Python version in semver-compatible format (e.g., "3.9.7") which is then validated against the requirement using semantic versioning rules.