MCPcopy Create free account
hub / github.com/KnockOutEZ/wigolo / checkVenvModule

Function checkVenvModule

src/python-env.ts:70–95  ·  view source on GitHub ↗
(pythonExe: string = resolvePythonExe())

Source from the content-addressed store, hash-verified

68 * exact package name (`python3.12-venv` for Python 3.12).
69 */
70export 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

Callers 3

runSearxngPhaseFunction · 0.85
bootstrapNativeSearxngFunction · 0.85

Calls 1

resolvePythonExeFunction · 0.85

Tested by

no test coverage detected