()
| 116 | } |
| 117 | |
| 118 | export async function resolvePythonExecutablePath(): Promise<string | undefined> { |
| 119 | if (cachedPythonPath !== undefined) { |
| 120 | return cachedPythonPath ?? undefined; |
| 121 | } |
| 122 | const candidates = findExecutablesOnPath(["python3", "python"]); |
| 123 | for (const candidate of candidates) { |
| 124 | const res = await runCommandWithTimeout( |
| 125 | [candidate, "-c", "import os, sys; print(os.path.realpath(sys.executable))"], |
| 126 | { timeoutMs: 2_000 }, |
| 127 | ); |
| 128 | if (res.code !== 0) { |
| 129 | continue; |
| 130 | } |
| 131 | const resolved = res.stdout.trim().split(/\s+/)[0]; |
| 132 | if (!resolved) { |
| 133 | continue; |
| 134 | } |
| 135 | try { |
| 136 | fs.accessSync(resolved, fs.constants.X_OK); |
| 137 | cachedPythonPath = resolved; |
| 138 | return resolved; |
| 139 | } catch { |
| 140 | // keep scanning |
| 141 | } |
| 142 | } |
| 143 | cachedPythonPath = null; |
| 144 | return undefined; |
| 145 | } |
| 146 | |
| 147 | async function gcloudEnv(): Promise<NodeJS.ProcessEnv | undefined> { |
| 148 | if (process.env.CLOUDSDK_PYTHON) { |
no test coverage detected