( platform: NodeJS.Platform, runCommand: CommandRunner, venvPythonPath?: string, customPythonPath?: string | null, )
| 101 | } |
| 102 | |
| 103 | export async function detectPythonRuntime( |
| 104 | platform: NodeJS.Platform, |
| 105 | runCommand: CommandRunner, |
| 106 | venvPythonPath?: string, |
| 107 | customPythonPath?: string | null, |
| 108 | ): Promise<PythonRuntimeResolution> { |
| 109 | const normalizedCustomPath = customPythonPath?.trim() |
| 110 | if (normalizedCustomPath) { |
| 111 | const customResult = await runCommand(normalizedCustomPath, ['--version']) |
| 112 | if (customResult.ok) { |
| 113 | return { |
| 114 | installed: true, |
| 115 | version: extractPythonVersion(`${customResult.stdout}\n${customResult.stderr}`), |
| 116 | path: normalizedCustomPath, |
| 117 | command: normalizedCustomPath, |
| 118 | prefixArgs: [], |
| 119 | source: 'custom', |
| 120 | error: null, |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return { |
| 125 | installed: false, |
| 126 | version: null, |
| 127 | path: normalizedCustomPath, |
| 128 | command: normalizedCustomPath, |
| 129 | prefixArgs: [], |
| 130 | source: 'custom', |
| 131 | error: customResult.stderr || customResult.stdout || `Failed to run ${normalizedCustomPath}`, |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | for (const candidate of getPythonCandidates(platform)) { |
| 136 | const versionResult = await runCommand(candidate.command, [...candidate.prefixArgs, '--version']) |
| 137 | if (!versionResult.ok) continue |
| 138 | |
| 139 | return { |
| 140 | installed: true, |
| 141 | version: extractPythonVersion(`${versionResult.stdout}\n${versionResult.stderr}`), |
| 142 | path: await locateCandidatePath(candidate, runCommand), |
| 143 | command: candidate.command, |
| 144 | prefixArgs: candidate.prefixArgs, |
| 145 | source: 'system', |
| 146 | error: null, |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if (venvPythonPath) { |
| 151 | const venvResult = await runCommand(venvPythonPath, ['--version']) |
| 152 | if (venvResult.ok) { |
| 153 | return { |
| 154 | installed: true, |
| 155 | version: extractPythonVersion(`${venvResult.stdout}\n${venvResult.stderr}`), |
| 156 | path: venvPythonPath, |
| 157 | command: venvPythonPath, |
| 158 | prefixArgs: [], |
| 159 | source: 'venv', |
| 160 | error: null, |
no test coverage detected