* Try a single Python candidate. Returns { exe, version } or null. * `candidate` is either a bare name or an array of args (e.g. ['py', '-3']).
(candidate)
| 90 | * `candidate` is either a bare name or an array of args (e.g. ['py', '-3']). |
| 91 | */ |
| 92 | function tryPythonCandidate(candidate) { |
| 93 | const args = Array.isArray(candidate) ? candidate : [candidate]; |
| 94 | const exe = args[0]; |
| 95 | const extraArgs = args.slice(1); |
| 96 | |
| 97 | try { |
| 98 | const out = execFileSync(exe, [...extraArgs, '--version'], { |
| 99 | encoding: 'utf8', |
| 100 | timeout: 10_000, |
| 101 | stdio: ['pipe', 'pipe', 'pipe'], |
| 102 | }); |
| 103 | |
| 104 | const ver = parsePythonVersion(out); |
| 105 | if (!ver) return null; |
| 106 | |
| 107 | // Require 3.11+ |
| 108 | if (ver.major < 3 || (ver.major === 3 && ver.minor < 11)) { |
| 109 | return { exe: args.join(' '), version: ver, tooOld: true }; |
| 110 | } |
| 111 | |
| 112 | return { exe: args.join(' '), version: ver, tooOld: false }; |
| 113 | } catch { |
| 114 | return null; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // --------------------------------------------------------------------------- |
| 119 | // Python detection |
no test coverage detected