forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-python.mjs
More file actions
49 lines (44 loc) · 1.32 KB
/
Copy pathrun-python.mjs
File metadata and controls
49 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
// Cross-platform Python launcher. POSIX systems usually expose `python3`,
// Windows usually exposes `python` (and sometimes the `py` launcher).
// Tries each in turn so package.json scripts don't have to.
//
// Usage:
// node packages/scripts/run-python.mjs -m pytest path/to/tests -v
// node packages/scripts/run-python.mjs script.py arg1 arg2
import { spawnSync } from "node:child_process";
const candidates =
process.platform === "win32"
? ["python", "python3", "py"]
: ["python3", "python"];
const args = process.argv.slice(2);
if (args.length === 0) {
console.error("Usage: node packages/scripts/run-python.mjs <args...>");
process.exit(2);
}
let lastError;
for (const cmd of candidates) {
const probe = spawnSync(cmd, ["--version"], {
stdio: "ignore",
shell: process.platform === "win32",
});
if (probe.error || probe.status !== 0) {
lastError = probe.error;
continue;
}
const result = spawnSync(cmd, args, {
stdio: "inherit",
env: process.env,
shell: process.platform === "win32",
});
if (result.error) {
console.error(result.error);
process.exit(1);
}
process.exit(result.status ?? 1);
}
console.error(
`[run-python] No Python interpreter found. Tried: ${candidates.join(", ")}.`,
);
if (lastError) console.error(lastError);
process.exit(1);