Files
maskanx_cm_backend/scripts/run-python.cjs
T

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-08-01 10:28:22 +05:30
#!/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);