mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
committed by
GitHub
parent
cd95a42e5e
commit
d9bf5cae12
@@ -10,7 +10,11 @@ import pyscript from "./stdlib/pyscript.js";
|
||||
|
||||
const { entries } = Object;
|
||||
|
||||
const python = ["from pathlib import Path as _Path", "_path = None"];
|
||||
const python = [
|
||||
"import os as _os",
|
||||
"from pathlib import Path as _Path",
|
||||
"_path = None",
|
||||
];
|
||||
|
||||
const write = (base, literal) => {
|
||||
for (const [key, value] of entries(literal)) {
|
||||
@@ -19,7 +23,9 @@ const write = (base, literal) => {
|
||||
const code = JSON.stringify(value);
|
||||
python.push(`_path.write_text(${code})`);
|
||||
} else {
|
||||
python.push("_path.mkdir(parents=True, exist_ok=True)");
|
||||
// @see https://github.com/pyscript/pyscript/pull/1813#issuecomment-1781502909
|
||||
python.push(`if not _os.path.exists("${base}/${key}"):`);
|
||||
python.push(" _path.mkdir(parents=True, exist_ok=True)");
|
||||
write(`${base}/${key}`, value);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +35,7 @@ write(".", pyscript);
|
||||
|
||||
python.push("del _Path");
|
||||
python.push("del _path");
|
||||
python.push("del _os");
|
||||
python.push("\n");
|
||||
|
||||
export default python.join("\n");
|
||||
|
||||
Reference in New Issue
Block a user