mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
[next] Bring in stdlib as artifact (#1666)
This commit is contained in:
committed by
GitHub
parent
da3b43abdd
commit
ef44df5dda
33
pyscript.core/src/stdlib.js
Normal file
33
pyscript.core/src/stdlib.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Create through Python the pyscript module through
|
||||
* the artifact generated at build time.
|
||||
* This the returned value is a string that must be used
|
||||
* either before a worker execute code or when the module
|
||||
* is registered on the main thread.
|
||||
*/
|
||||
|
||||
import pyscript from "./stdlib/pyscript.js";
|
||||
|
||||
const { entries } = Object;
|
||||
|
||||
const python = ["from pathlib import Path as _Path"];
|
||||
|
||||
const write = (base, literal) => {
|
||||
for (const [key, value] of entries(literal)) {
|
||||
const path = `_Path("${base}/${key}")`;
|
||||
if (typeof value === "string") {
|
||||
const code = JSON.stringify(value);
|
||||
python.push(`${path}.write_text(${code})`);
|
||||
} else {
|
||||
python.push(`${path}.mkdir(parents=True, exist_ok=True)`);
|
||||
write(`${base}/${key}`, value);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
write(".", pyscript);
|
||||
|
||||
python.push("del _Path");
|
||||
python.push("\n");
|
||||
|
||||
export default python.join("\n");
|
||||
Reference in New Issue
Block a user