Path: blob/main/desktop/electron/src/python-frontend.ts
1067 views
export default async function python() {1const element = document.createElement("pre");2document.body.appendChild(element);3console.log("This is python...!");4let t0 = performance.now();5await window.electronAPI.pythonExec("import os, sys");6element.innerText = `Python startup time: ${performance.now() - t0}ms\n`;7t0 = performance.now();8const v = await window.electronAPI.pythonRepr("sys.version");9console.log(v);10element.innerText +=11"\n" + v.slice(1, -1) + `\nTime: ${performance.now() - t0}ms\n`;1213// filesystem14element.innerText +=15"\nNative Files:\n" +16(await window.electronAPI.pythonRepr("' '.join(os.listdir('.'))")) +17"\n";1819await window.electronAPI.pythonExec(`20import pandas21from contextlib import redirect_stdout22import io23f = io.StringIO()24with redirect_stdout(f):25print("PYTHONHOME = ", os.environ.get('PYTHONHOME'))26print("sys.path = ", sys.path)27pandas.show_versions()28s = f.getvalue()29`);30let pv = await window.electronAPI.pythonRepr("s");31console.log(pv);32pv = pv.split("\\n").join("\n").slice(1, -1);33console.log(pv);34pv = `Time to import pandas and get versions: ${Math.round(35performance.now() - t036)}ms\n${pv}`;37element.innerText += "\n" + pv;38}394041