Implemented pyminify for our stdlib (#2140)

* Implemented pyminify for our stdlib

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Andrea Giammarchi
2024-08-07 12:33:20 +02:00
committed by GitHub
parent 7166c32384
commit f4c4edeb29
5 changed files with 626 additions and 42 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.5.3",
"version": "0.5.5",
"type": "module",
"description": "PyScript",
"module": "./index.js",
@@ -55,7 +55,7 @@
"@codemirror/language": "^6.10.2",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.30.0",
"@playwright/test": "^1.45.3",
"@playwright/test": "1.45.3",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",

View File

@@ -4,13 +4,27 @@ const {
statSync,
writeFileSync,
} = require("node:fs");
const { spawnSync } = require("node:child_process");
const { join } = require("node:path");
const crawl = (path, json) => {
for (const file of readdirSync(path)) {
const full = join(path, file);
if (/\.py$/.test(file)) json[file] = readFileSync(full).toString();
else if (statSync(full).isDirectory() && !file.endsWith("_"))
if (/\.py$/.test(file)) {
if (process.env.NO_MIN) json[file] = readFileSync(full).toString();
else {
const {
output: [error, result],
} = spawnSync("pyminify", [
"--remove-literal-statements",
full,
]);
if (error) process.exit(1);
json[file] = result.toString();
}
} else if (statSync(full).isDirectory() && !file.endsWith("_"))
crawl(full, (json[file] = {}));
}
};

View File

@@ -11,3 +11,5 @@ micropip==0.5.0
toml==0.10.2
numpy==1.26.4
pillow==10.3.0
python-minifier==2.9.0
setuptools==72.1.0