mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
committed by
GitHub
parent
e67eb06d8b
commit
cd95a42e5e
@@ -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