MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / runPythonWithStdin

Function runPythonWithStdin

src/ast/extract-python.ts:557–590  ·  view source on GitHub ↗
(script: string, source: string, filename: string)

Source from the content-addressed store, hash-verified

555
556 pythonAvailable = false;
557 return false;
558}
559
560import { spawn } from "node:child_process";
561
562async function runPythonWithStdin(script: string, source: string, filename: string): Promise<any> {
563 if (!(await findPython())) return null;
564
565 return new Promise((resolve) => {
566 const proc = spawn(pythonCmd, ["-c", script, filename], {
567 timeout: 10000,
568 env: { ...process.env, PYTHONDONTWRITEBYTECODE: "1" },
569 stdio: ["pipe", "pipe", "pipe"],
570 });
571
572 let stdout = "";
573 let stderr = "";
574
575 proc.stdout.on("data", (data: Buffer) => { stdout += data.toString(); });
576 proc.stderr.on("data", (data: Buffer) => { stderr += data.toString(); });
577
578 proc.on("close", (code) => {
579 if (code !== 0 || !stdout.trim()) {
580 resolve(null);
581 return;
582 }
583 try {
584 resolve(JSON.parse(stdout.trim()));
585 } catch {
586 resolve(null);
587 }
588 });
589
590 proc.on("error", () => resolve(null));
591
592 proc.stdin.write(source);
593 proc.stdin.end();

Callers 4

extractPythonRoutesASTFunction · 0.85
extractSQLAlchemyASTFunction · 0.85
extractDjangoModelsASTFunction · 0.85
extractSQLModelASTFunction · 0.85

Calls 1

findPythonFunction · 0.85

Tested by

no test coverage detected