52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|||
|
|
const { existsSync } = require("node:fs");
|
||
|
|
const { join } = require("node:path");
|
||
|
|
const { spawnSync } = require("node:child_process");
|
||
|
|
|
||
|
|
const isWindows = process.platform === "win32";
|
||
|
|
const candidates = [];
|
||
|
|
|
||
|
|
if (process.env.PYTHON) {
|
||
|
|
candidates.push(process.env.PYTHON);
|
||
|
|
}
|
||
|
|
|
||
|
|
candidates.push(
|
||
|
|
isWindows
|
||
|
|
? join(process.cwd(), ".venv311", "Scripts", "python.exe")
|
||
|
|
: join(process.cwd(), ".venv311", "bin", "python"),
|
||
|
|
isWindows
|
||
|
|
? join(process.cwd(), ".venv", "Scripts", "python.exe")
|
||
|
|
: join(process.cwd(), ".venv", "bin", "python"),
|
||
|
|
isWindows
|
||
|
|
? join(process.cwd(), "..", ".venv311", "Scripts", "python.exe")
|
||
|
|
: join(process.cwd(), "..", ".venv311", "bin", "python"),
|
||
|
|
"python3",
|
||
|
|
"python",
|
||
|
|
"py",
|
||
|
|
);
|
||
|
|
|
||
|
|
const args = process.argv.slice(2);
|
||
|
|
|
||
|
|
for (const candidate of candidates) {
|
||
|
|
const isPath = candidate.includes("/") || candidate.includes("\\");
|
||
|
|
if (isPath && !existsSync(candidate)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
const result = spawnSync(candidate, args, {
|
||
|
|
stdio: "inherit",
|
||
|
|
shell: false,
|
||
|
|
env: process.env,
|
||
|
|
});
|
||
|
|
if (result.error) {
|
||
|
|
if (result.error.code === "ENOENT") {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
console.error(result.error.message);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
process.exit(result.status ?? 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
console.error("No Python executable found. Set PYTHON or create .venv311.");
|
||
|
|
process.exit(1);
|