CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-autorest--system-requirements

System requirement validation and resolution for autorest.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

python-requirements.mddocs/

Python Requirements Resolution

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.

Capabilities

Python Requirement Resolution

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"
});

Python Command Path Patching

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);
}

Deprecated Python Path Update

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[]>;

Python Detection Logic

The Python resolver follows this detection order:

  1. Environment Variable: If environmentVariable is specified in the requirement, or AUTOREST_PYTHON_EXE is set
  2. Windows py.exe: On Windows, tries py -3 command
  3. python3: Tries python3 executable
  4. python: Tries python executable

Each candidate is tested by executing a version detection script to verify it's a working Python interpreter with the correct version.

Python-Specific Types

/** 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[]];

Constants

/** Python requirement identifier used in system requirement resolution */
const PythonRequirement = "python";

Version Detection

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.

docs

core-resolution.md

dotnet-requirements.md

generic-resolution.md

index.md

java-requirements.md

python-requirements.md

tile.json