MCPcopy Create free account
hub / github.com/DustinBrett/daedalOS / runPython

Function runPython

components/apps/Terminal/python.ts:32–65  ·  view source on GitHub ↗
(
  code: string,
  printLn: (message: string) => void
)

Source from the content-addressed store, hash-verified

30 "import sys\r\nimport io\r\nsys.stdout = io.StringIO()\r\n";
31
32export const runPython = async (
33 code: string,
34 printLn: (message: string) => void
35): Promise<void> => {
36 await loadFiles(["/Program Files/Pyodide/pyodide.js"]);
37
38 if (!window.pyodide && window.loadPyodide) {
39 window.pyodide = await window.loadPyodide(config);
40 }
41
42 if (window.pyodide) {
43 const getVersion = code === "ver" || code === "version";
44
45 try {
46 if (code.includes("import micropip")) {
47 await window.pyodide.loadPackage("micropip", { checkIntegrity: false });
48 }
49
50 let result = await window.pyodide.runPythonAsync(
51 getVersion ? versionCommand : captureStdOut + code
52 );
53
54 if (!result) {
55 result = await window.pyodide.runPythonAsync("sys.stdout.getvalue()");
56 }
57
58 if (result) printLn(result);
59 } catch (error) {
60 const { message } = error as PyError;
61
62 if (message) printLn(message);
63 }
64 }
65};

Callers 1

useCommandInterpreterFunction · 0.90

Calls 3

loadFilesFunction · 0.90
includesMethod · 0.80
runPythonAsyncMethod · 0.80

Tested by

no test coverage detected