Fix #1812 - Avoid duplicated pyscript module (#1813)

This commit is contained in:
Andrea Giammarchi
2023-10-26 19:44:31 +02:00
committed by GitHub
parent e67eb06d8b
commit cd95a42e5e
2 changed files with 5 additions and 7 deletions

View File

@@ -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");