26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
|
|
// lib/python.ts
|
||
|
|
// Resolve the Python interpreter the workbench should spawn for
|
||
|
|
// running scripts in scripts/.
|
||
|
|
//
|
||
|
|
// The capture + push scripts import third-party modules (requests,
|
||
|
|
// playwright, dotenv) that are tracked in scripts/requirements.txt
|
||
|
|
// but only installed inside scripts/.venv/. Spawning bare `python`
|
||
|
|
// resolves to the system Python (e.g. C:\Users\SJ\AppData\Local\Programs\Python\Python311\python.exe),
|
||
|
|
// which does NOT have these modules → ModuleNotFoundError at import.
|
||
|
|
//
|
||
|
|
// Prefer the venv Python; fall back to `python` (PATH lookup) if
|
||
|
|
// the venv doesn't exist for some reason.
|
||
|
|
|
||
|
|
import { existsSync } from "node:fs";
|
||
|
|
import path from "node:path";
|
||
|
|
|
||
|
|
const SCRIPTS_DIR = path.join(process.cwd(), "scripts");
|
||
|
|
|
||
|
|
export function getPythonExecutable(): string {
|
||
|
|
const venvPythonWin = path.join(SCRIPTS_DIR, ".venv", "Scripts", "python.exe");
|
||
|
|
const venvPythonPosix = path.join(SCRIPTS_DIR, ".venv", "bin", "python");
|
||
|
|
if (existsSync(venvPythonWin)) return venvPythonWin;
|
||
|
|
if (existsSync(venvPythonPosix)) return venvPythonPosix;
|
||
|
|
return "python"; // fallback — caller will get a clear error if it doesn't have the deps
|
||
|
|
}
|