mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
committed by
GitHub
parent
e67eb06d8b
commit
cd95a42e5e
@@ -21,7 +21,6 @@ import "./all-done.js";
|
||||
import TYPES from "./types.js";
|
||||
import configs from "./config.js";
|
||||
import sync from "./sync.js";
|
||||
import stdlib from "./stdlib.js";
|
||||
import bootstrapNodeAndPlugins from "./plugins-helper.js";
|
||||
import { ErrorCode } from "./exceptions.js";
|
||||
import { robustFetch as fetch, getText } from "./fetch.js";
|
||||
@@ -52,8 +51,6 @@ const registerModule = ({ XWorker: $XWorker, interpreter, io }) => {
|
||||
: currentElement.id;
|
||||
},
|
||||
});
|
||||
|
||||
interpreter.runPython(stdlib, { globals: interpreter.runPython("{}") });
|
||||
};
|
||||
|
||||
// avoid multiple initialization of the same library
|
||||
|
||||
@@ -10,16 +10,16 @@ import pyscript from "./stdlib/pyscript.js";
|
||||
|
||||
const { entries } = Object;
|
||||
|
||||
const python = ["from pathlib import Path as _Path"];
|
||||
const python = ["from pathlib import Path as _Path", "_path = None"];
|
||||
|
||||
const write = (base, literal) => {
|
||||
for (const [key, value] of entries(literal)) {
|
||||
const path = `_Path("${base}/${key}")`;
|
||||
python.push(`_path = _Path("${base}/${key}")`);
|
||||
if (typeof value === "string") {
|
||||
const code = JSON.stringify(value);
|
||||
python.push(`${path}.write_text(${code})`);
|
||||
python.push(`_path.write_text(${code})`);
|
||||
} else {
|
||||
python.push(`${path}.mkdir(parents=True, exist_ok=True)`);
|
||||
python.push("_path.mkdir(parents=True, exist_ok=True)");
|
||||
write(`${base}/${key}`, value);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ const write = (base, literal) => {
|
||||
write(".", pyscript);
|
||||
|
||||
python.push("del _Path");
|
||||
python.push("del _path");
|
||||
python.push("\n");
|
||||
|
||||
export default python.join("\n");
|
||||
|
||||
Reference in New Issue
Block a user