MCPcopy Create free account
hub / github.com/AnkRoot/Augment-BYOK / resolvePythonSpec

Function resolvePythonSpec

tools/lib/run.js:12–34  ·  view source on GitHub ↗
({ cwd, spawnSyncImpl, useCache } = {})

Source from the content-addressed store, hash-verified

10}
11
12function resolvePythonSpec({ cwd, spawnSyncImpl, useCache } = {}) {
13 const runner = typeof spawnSyncImpl === "function" ? spawnSyncImpl : spawnSync;
14 const canUseCache = useCache !== false;
15 if (canUseCache && cachedPythonSpec && typeof cachedPythonSpec.cmd === "string") {
16 return { cmd: cachedPythonSpec.cmd, argsPrefix: [...cachedPythonSpec.argsPrefix] };
17 }
18
19 const candidates = [{ cmd: "python3", argsPrefix: [] }, { cmd: "py", argsPrefix: ["-3"] }, { cmd: "python", argsPrefix: [] }];
20 for (const spec of candidates) {
21 const probe = runner(spec.cmd, [...spec.argsPrefix, "--version"], { cwd, stdio: "ignore" });
22 if (probe?.error) {
23 if (probe.error.code === "ENOENT") continue;
24 continue;
25 }
26 if (probe?.status === 0) {
27 const resolved = { cmd: spec.cmd, argsPrefix: [...spec.argsPrefix] };
28 if (canUseCache) cachedPythonSpec = resolved;
29 return resolved;
30 }
31 }
32
33 throw new Error("python runtime not found (tried: python3, py -3, python)");
34}
35
36function runPython(args, { cwd } = {}) {
37 const spec = resolvePythonSpec({ cwd });

Callers 2

runPythonFunction · 0.85
run-python.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected