(pythonExe: string = resolvePythonExe())
| 68 | * exact package name (`python3.12-venv` for Python 3.12). |
| 69 | */ |
| 70 | export function checkVenvModule(pythonExe: string = resolvePythonExe()): VenvModuleCheck { |
| 71 | const result: VenvModuleCheck = { available: false }; |
| 72 | |
| 73 | const version = spawnSync( |
| 74 | pythonExe, |
| 75 | ['-c', "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"], |
| 76 | { encoding: 'utf-8' }, |
| 77 | ); |
| 78 | if (version.status !== 0 || version.error) { |
| 79 | // The interpreter itself could not run — that is a "python not available" |
| 80 | // problem, not a "venv module missing" one. Report available=true so the |
| 81 | // caller's normal flow surfaces the real interpreter error rather than a |
| 82 | // misleading apt hint. |
| 83 | result.available = true; |
| 84 | return result; |
| 85 | } |
| 86 | const parsed = version.stdout.trim(); |
| 87 | if (/^\d+\.\d+$/.test(parsed)) result.pythonVersion = parsed; |
| 88 | |
| 89 | // `import ensurepip, venv` is the classic missing-python3-venv tripwire on |
| 90 | // Debian: the venv module is present in stdlib but ensurepip is shipped in |
| 91 | // the separate `python3-venv` apt package. |
| 92 | const probe = spawnSync(pythonExe, ['-c', 'import ensurepip, venv'], { encoding: 'utf-8' }); |
| 93 | result.available = probe.status === 0 && !probe.error; |
| 94 | return result; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns true when the given stderr is the recognizable "python3-venv package |
no test coverage detected