korpress 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- korpress-0.1.0a1/.agents/skills/korpress/SKILL.md +119 -0
- korpress-0.1.0a1/.github/workflows/ci.yml +97 -0
- korpress-0.1.0a1/.github/workflows/docs.yml +54 -0
- korpress-0.1.0a1/.github/workflows/release.yml +204 -0
- korpress-0.1.0a1/.gitignore +15 -0
- korpress-0.1.0a1/AGENTS.md +53 -0
- korpress-0.1.0a1/CHANGELOG.md +14 -0
- korpress-0.1.0a1/CLAUDE.md +1 -0
- korpress-0.1.0a1/CONTRIBUTING.md +142 -0
- korpress-0.1.0a1/Cargo.lock +132 -0
- korpress-0.1.0a1/Cargo.toml +33 -0
- korpress-0.1.0a1/LICENSE +21 -0
- korpress-0.1.0a1/PKG-INFO +103 -0
- korpress-0.1.0a1/README.md +74 -0
- korpress-0.1.0a1/docs/ai.md +34 -0
- korpress-0.1.0a1/docs/cli.md +387 -0
- korpress-0.1.0a1/docs/css.md +194 -0
- korpress-0.1.0a1/docs/glossary.md +63 -0
- korpress-0.1.0a1/docs/html.md +300 -0
- korpress-0.1.0a1/docs/index.md +53 -0
- korpress-0.1.0a1/docs/js.md +200 -0
- korpress-0.1.0a1/docs/korvex.md +117 -0
- korpress-0.1.0a1/docs/limits.md +124 -0
- korpress-0.1.0a1/docs/reference/korpress.md +12 -0
- korpress-0.1.0a1/docs/rust.md +94 -0
- korpress-0.1.0a1/docs/tutorial.md +339 -0
- korpress-0.1.0a1/examples/min.rs +69 -0
- korpress-0.1.0a1/mkdocs.yml +94 -0
- korpress-0.1.0a1/pyproject.toml +83 -0
- korpress-0.1.0a1/python/korpress/__init__.py +134 -0
- korpress-0.1.0a1/python/korpress/__main__.py +7 -0
- korpress-0.1.0a1/python/korpress/_korpress.pyi +114 -0
- korpress-0.1.0a1/python/korpress/_skill/SKILL.md +119 -0
- korpress-0.1.0a1/python/korpress/cli.py +225 -0
- korpress-0.1.0a1/python/korpress/py.typed +0 -0
- korpress-0.1.0a1/src/css.rs +1248 -0
- korpress-0.1.0a1/src/error.rs +50 -0
- korpress-0.1.0a1/src/html.rs +1161 -0
- korpress-0.1.0a1/src/js.rs +1342 -0
- korpress-0.1.0a1/src/lib.rs +22 -0
- korpress-0.1.0a1/src/python.rs +165 -0
- korpress-0.1.0a1/tests/corpus/README.md +21 -0
- korpress-0.1.0a1/tests/corpus/css_diff.js +14 -0
- korpress-0.1.0a1/tests/corpus/html_dom.js +52 -0
- korpress-0.1.0a1/tests/corpus/js_ast.js +44 -0
- korpress-0.1.0a1/tests/corpus/js_firstdiff.js +15 -0
- korpress-0.1.0a1/tests/corpus/package.json +10 -0
- korpress-0.1.0a1/tests/test_agent_skill.py +34 -0
- korpress-0.1.0a1/tests/test_api.py +128 -0
- korpress-0.1.0a1/tests/test_cli.py +193 -0
- korpress-0.1.0a1/tests/test_docs_snippets.py +103 -0
- korpress-0.1.0a1/tests/test_node.py +107 -0
- korpress-0.1.0a1/uv.lock +1438 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: korpress
|
|
3
|
+
description: Minify HTML, CSS and JavaScript with korpress, the Rust minifier for Python. Use when code imports korpress, or when asked to shrink web assets at build time, for a Korvex app or any other.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# korpress
|
|
7
|
+
|
|
8
|
+
korpress makes HTML, CSS and JavaScript files smaller by removing spaces and
|
|
9
|
+
comments. It is written in Rust and has no Python dependencies. Python 3.10
|
|
10
|
+
or later. It is Alpha: the API can change before 1.0, so check
|
|
11
|
+
`korpress.__version__`.
|
|
12
|
+
|
|
13
|
+
Only alphas exist, so install with `--pre`: `pip install --pre korpress`.
|
|
14
|
+
|
|
15
|
+
## The API
|
|
16
|
+
|
|
17
|
+
Every function takes a `str` and returns a `str`.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from korpress import minify_css, minify_html, minify_js
|
|
21
|
+
|
|
22
|
+
assert minify_css("a { color : red ; }") == "a{color:red}"
|
|
23
|
+
assert minify_js("var total = 1 ; var count = 2 ;") == "var total=1;var count=2;"
|
|
24
|
+
|
|
25
|
+
page = "<p> hi </p> <!-- note -->\n<style>a { color : red }</style><script>var a = 1 ;</script>"
|
|
26
|
+
assert minify_html(page) == "<p>hi</p><style>a{color:red}</style><script>var a=1</script>"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`minify(src, kind)` picks the function from `kind` (`"html"`, `"css"` or
|
|
30
|
+
`"js"`; anything else raises `ValueError`) and passes extra options on:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from korpress import minify
|
|
34
|
+
|
|
35
|
+
assert minify("a { color : red ; }", "css") == "a{color:red}"
|
|
36
|
+
assert minify("/*! MIT */ a { color : red }", "css", keep_important_comments=False) == "a{color:red}"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`minify_file(path, out=None, *, kind=None, **options)` reads a UTF-8 file,
|
|
40
|
+
writes the result and returns `(size_before, size_after)` in bytes. Without
|
|
41
|
+
`out` it overwrites `path`. Missing folders in `out` are created. `kind` comes
|
|
42
|
+
from the extension (`.html .htm .css .js .mjs .cjs`) unless you give it. The
|
|
43
|
+
write goes through a temporary file, so a failure never damages the target.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import pathlib
|
|
47
|
+
import tempfile
|
|
48
|
+
|
|
49
|
+
from korpress import minify_file
|
|
50
|
+
|
|
51
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
52
|
+
src = pathlib.Path(tmp, "app.js")
|
|
53
|
+
src.write_text("var a = 1 ;\n")
|
|
54
|
+
before, after = minify_file(src, pathlib.Path(tmp, "dist", "app.min.js"))
|
|
55
|
+
assert (before, after) == (12, 8)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The command line does the same for files and folders:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
korpress style.css # print the result
|
|
62
|
+
korpress style.css -o style.min.css # write a new file
|
|
63
|
+
korpress page.html --in-place # overwrite
|
|
64
|
+
korpress src/ -o dist/ --copy # a folder; --copy also copies images and the rest
|
|
65
|
+
echo 'var a = 1 ;' | korpress -t js # stdin needs --type html|css|js
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Several files or a folder need `--output` or `--in-place`. Files with `.min.`
|
|
69
|
+
in the name, hidden folders and `node_modules` are skipped in a folder. `-q`
|
|
70
|
+
hides the sizes. Exit code: 0 on success, 1 if a file failed, 2 for a usage
|
|
71
|
+
error.
|
|
72
|
+
|
|
73
|
+
## Rules that differ from other minifiers
|
|
74
|
+
|
|
75
|
+
- **No renaming, no rewriting.** korpress only removes bytes the browser does
|
|
76
|
+
not need. Variable names, property names and the code stay as written. If
|
|
77
|
+
you need mangling or dead-code removal, use a bundler.
|
|
78
|
+
- **Errors carry a position.** `minify_js` raises `KorpressError` (a
|
|
79
|
+
`ValueError`) for an unterminated string, template, regular expression or
|
|
80
|
+
block comment. It has `.line` and `.column`, both 1-based, and nothing is
|
|
81
|
+
returned. HTML and CSS never raise today: bad CSS passes through, and an
|
|
82
|
+
inline script that cannot be minified is left as it is.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from korpress import KorpressError, minify_js
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
minify_js('var a = "oops;')
|
|
89
|
+
except KorpressError as err:
|
|
90
|
+
assert (err.line, err.column) == (1, 9)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- **Inline code is handled.** `minify_html` also minifies `<style>` blocks,
|
|
94
|
+
`<script>` blocks and `style=""` attributes. Turn it off with
|
|
95
|
+
`minify_css=False` or `minify_js=False`. It keeps `<pre>`, `<textarea>`,
|
|
96
|
+
conditional comments and scripts of unknown type as they are.
|
|
97
|
+
- **License comments stay.** `/*! ... */` is kept by default; pass
|
|
98
|
+
`keep_important_comments=False` (CLI: `--strip-license`) to drop it.
|
|
99
|
+
- **Use it at build time, not per request.** Minify once when you build or
|
|
100
|
+
deploy and serve the files. Do not call it in a request handler.
|
|
101
|
+
- **Pair it with Korvex.** Write the minified files into the static folder,
|
|
102
|
+
compress them in the same build step, and serve them with
|
|
103
|
+
`app.static("/static", "public", precompressed=True)`. Nothing is
|
|
104
|
+
minified or compressed while serving.
|
|
105
|
+
|
|
106
|
+
## Common mistakes
|
|
107
|
+
|
|
108
|
+
- Minifying inside a handler or on every page render: do it in the build.
|
|
109
|
+
- Expecting short names or tree shaking: korpress does neither.
|
|
110
|
+
- Passing a `bytes` or a path to `minify_html`, `minify_css` or `minify_js`:
|
|
111
|
+
they take source text. Use `minify_file` for a path.
|
|
112
|
+
- Minifying a file that is already `app.min.js`: the CLI skips it in a
|
|
113
|
+
folder, but `minify_file` does not.
|
|
114
|
+
- Passing an unknown `kind`, or a file extension korpress cannot guess,
|
|
115
|
+
without `kind=` (or `--type`): it raises `ValueError`.
|
|
116
|
+
- Overwriting your source files by mistake: write to a separate `dist/`
|
|
117
|
+
folder (`-o dist/`) and keep `--in-place` for build output only.
|
|
118
|
+
- Catching only `KorpressError` for a file read: a file that is not UTF-8
|
|
119
|
+
raises `UnicodeDecodeError`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
# A new push to a pull request stops the run of the one before.
|
|
12
|
+
concurrency:
|
|
13
|
+
group: ci-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
lint:
|
|
18
|
+
name: Lint, types and Rust tests
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
timeout-minutes: 20
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v7
|
|
23
|
+
with:
|
|
24
|
+
persist-credentials: false
|
|
25
|
+
|
|
26
|
+
- name: Install Rust
|
|
27
|
+
uses: dtolnay/rust-toolchain@stable
|
|
28
|
+
with:
|
|
29
|
+
components: rustfmt, clippy
|
|
30
|
+
|
|
31
|
+
- uses: Swatinem/rust-cache@v2
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
35
|
+
|
|
36
|
+
- name: Rust formatting
|
|
37
|
+
run: cargo fmt --check
|
|
38
|
+
|
|
39
|
+
- name: Clippy
|
|
40
|
+
run: cargo clippy --all-targets --features python -- -D warnings
|
|
41
|
+
|
|
42
|
+
- name: Rust tests
|
|
43
|
+
run: cargo test
|
|
44
|
+
|
|
45
|
+
- name: Install
|
|
46
|
+
run: uv sync --locked
|
|
47
|
+
|
|
48
|
+
- name: Ruff
|
|
49
|
+
run: uv run --no-sync ruff check --output-format=github .
|
|
50
|
+
|
|
51
|
+
- name: Python formatting
|
|
52
|
+
run: uv run --no-sync ruff format --check .
|
|
53
|
+
|
|
54
|
+
- name: Pyright
|
|
55
|
+
run: uv run --no-sync pyright
|
|
56
|
+
|
|
57
|
+
test:
|
|
58
|
+
# Python 3.14t is the free-threaded build. -W error::RuntimeWarning fails
|
|
59
|
+
# the run if any module turns the GIL back on, which would undo the point.
|
|
60
|
+
name: Python ${{ matrix.python }}
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
timeout-minutes: 30
|
|
63
|
+
strategy:
|
|
64
|
+
fail-fast: false
|
|
65
|
+
matrix:
|
|
66
|
+
python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.14t"]
|
|
67
|
+
steps:
|
|
68
|
+
- uses: actions/checkout@v7
|
|
69
|
+
with:
|
|
70
|
+
persist-credentials: false
|
|
71
|
+
|
|
72
|
+
- name: Install Rust
|
|
73
|
+
uses: dtolnay/rust-toolchain@stable
|
|
74
|
+
|
|
75
|
+
- uses: Swatinem/rust-cache@v2
|
|
76
|
+
|
|
77
|
+
- name: Install uv
|
|
78
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
79
|
+
|
|
80
|
+
- name: Install Node.js (for tests/test_node.py)
|
|
81
|
+
uses: actions/setup-node@v6
|
|
82
|
+
with:
|
|
83
|
+
node-version: lts/*
|
|
84
|
+
|
|
85
|
+
- name: Install dependencies
|
|
86
|
+
run: uv sync --locked --no-install-project --python ${{ matrix.python }}
|
|
87
|
+
|
|
88
|
+
- name: Build and install
|
|
89
|
+
run: uv run --no-sync maturin develop --release --uv
|
|
90
|
+
|
|
91
|
+
- name: Tests
|
|
92
|
+
if: matrix.python != '3.14t'
|
|
93
|
+
run: uv run --no-sync pytest
|
|
94
|
+
|
|
95
|
+
- name: Tests (free-threaded)
|
|
96
|
+
if: matrix.python == '3.14t'
|
|
97
|
+
run: uv run --no-sync python -m pytest -W error::RuntimeWarning
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
|
|
3
|
+
# Builds the documentation site on every pull request (a broken link or
|
|
4
|
+
# reference fails it), and publishes it to GitHub Pages from main.
|
|
5
|
+
# The reference is read from the source.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
branches: [main]
|
|
10
|
+
pull_request:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
concurrency:
|
|
16
|
+
group: docs-${{ github.ref }}
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
build:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
timeout-minutes: 10
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v7
|
|
25
|
+
with:
|
|
26
|
+
persist-credentials: false
|
|
27
|
+
|
|
28
|
+
- name: Install uv
|
|
29
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
30
|
+
|
|
31
|
+
- name: Build
|
|
32
|
+
env:
|
|
33
|
+
NO_MKDOCS_2_WARNING: "1"
|
|
34
|
+
run: uv run --python 3.13 --group docs mkdocs build --strict -d site
|
|
35
|
+
|
|
36
|
+
- name: Upload
|
|
37
|
+
if: github.event_name == 'push'
|
|
38
|
+
uses: actions/upload-pages-artifact@v5.0.0
|
|
39
|
+
with:
|
|
40
|
+
path: site
|
|
41
|
+
|
|
42
|
+
deploy:
|
|
43
|
+
if: github.event_name == 'push'
|
|
44
|
+
needs: build
|
|
45
|
+
runs-on: ubuntu-latest
|
|
46
|
+
permissions:
|
|
47
|
+
pages: write
|
|
48
|
+
id-token: write
|
|
49
|
+
environment:
|
|
50
|
+
name: github-pages
|
|
51
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
52
|
+
steps:
|
|
53
|
+
- id: deployment
|
|
54
|
+
uses: actions/deploy-pages@v5.0.1
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# On a `v*` tag: check the tag matches the version in pyproject.toml, build
|
|
2
|
+
# wheels for every platform, install each one in a fresh venv and smoke-test
|
|
3
|
+
# it, then publish to PyPI.
|
|
4
|
+
# Run by hand (workflow_dispatch) to build and test without publishing.
|
|
5
|
+
name: Release
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
tags:
|
|
10
|
+
- "v*"
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
env:
|
|
17
|
+
SMOKE_CODE: "import korpress; assert korpress.minify_css('a { b : c }') == 'a{b:c}'"
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
check-version:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
timeout-minutes: 10
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v7
|
|
25
|
+
with:
|
|
26
|
+
persist-credentials: false
|
|
27
|
+
- name: Check the tag matches the version
|
|
28
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
29
|
+
run: |
|
|
30
|
+
version=$(python3 -c "import tomllib;print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
31
|
+
test "v$version" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != v$version"; exit 1; }
|
|
32
|
+
|
|
33
|
+
linux:
|
|
34
|
+
needs: check-version
|
|
35
|
+
runs-on: ${{ matrix.runner }}
|
|
36
|
+
timeout-minutes: 30
|
|
37
|
+
strategy:
|
|
38
|
+
matrix:
|
|
39
|
+
include:
|
|
40
|
+
- { runner: ubuntu-22.04, target: x86_64 }
|
|
41
|
+
- { runner: ubuntu-24.04-arm, target: aarch64 }
|
|
42
|
+
steps:
|
|
43
|
+
- uses: actions/checkout@v7
|
|
44
|
+
with:
|
|
45
|
+
persist-credentials: false
|
|
46
|
+
- name: Build wheels
|
|
47
|
+
uses: PyO3/maturin-action@v1
|
|
48
|
+
with:
|
|
49
|
+
target: ${{ matrix.target }}
|
|
50
|
+
args: --release --out dist
|
|
51
|
+
manylinux: auto
|
|
52
|
+
- name: Smoke test wheel
|
|
53
|
+
run: |
|
|
54
|
+
python3 -m venv test-env
|
|
55
|
+
test-env/bin/pip install --quiet dist/*.whl
|
|
56
|
+
test-env/bin/python -I -c "$SMOKE_CODE"
|
|
57
|
+
test-env/bin/korpress --help
|
|
58
|
+
- uses: actions/upload-artifact@v7
|
|
59
|
+
with:
|
|
60
|
+
name: wheels-linux-${{ matrix.target }}
|
|
61
|
+
path: dist
|
|
62
|
+
|
|
63
|
+
macos:
|
|
64
|
+
needs: check-version
|
|
65
|
+
runs-on: ${{ matrix.runner }}
|
|
66
|
+
timeout-minutes: 30
|
|
67
|
+
strategy:
|
|
68
|
+
matrix:
|
|
69
|
+
include:
|
|
70
|
+
- { runner: macos-15-intel, target: x86_64 }
|
|
71
|
+
- { runner: macos-latest, target: aarch64 }
|
|
72
|
+
steps:
|
|
73
|
+
- uses: actions/checkout@v7
|
|
74
|
+
with:
|
|
75
|
+
persist-credentials: false
|
|
76
|
+
- name: Build wheels
|
|
77
|
+
uses: PyO3/maturin-action@v1
|
|
78
|
+
with:
|
|
79
|
+
target: ${{ matrix.target }}
|
|
80
|
+
args: --release --out dist
|
|
81
|
+
- name: Smoke test wheel
|
|
82
|
+
run: |
|
|
83
|
+
python3 -m venv test-env
|
|
84
|
+
test-env/bin/pip install --quiet dist/*.whl
|
|
85
|
+
test-env/bin/python -I -c "$SMOKE_CODE"
|
|
86
|
+
test-env/bin/korpress --help
|
|
87
|
+
- uses: actions/upload-artifact@v7
|
|
88
|
+
with:
|
|
89
|
+
name: wheels-macos-${{ matrix.target }}
|
|
90
|
+
path: dist
|
|
91
|
+
|
|
92
|
+
windows:
|
|
93
|
+
needs: check-version
|
|
94
|
+
runs-on: windows-latest
|
|
95
|
+
timeout-minutes: 30
|
|
96
|
+
steps:
|
|
97
|
+
- uses: actions/checkout@v7
|
|
98
|
+
with:
|
|
99
|
+
persist-credentials: false
|
|
100
|
+
- name: Build wheels
|
|
101
|
+
uses: PyO3/maturin-action@v1
|
|
102
|
+
with:
|
|
103
|
+
target: x64
|
|
104
|
+
args: --release --out dist
|
|
105
|
+
- name: Smoke test wheel
|
|
106
|
+
shell: bash
|
|
107
|
+
run: |
|
|
108
|
+
python -m venv test-env
|
|
109
|
+
test-env/Scripts/pip install --quiet dist/*.whl
|
|
110
|
+
test-env/Scripts/python -I -c "$SMOKE_CODE"
|
|
111
|
+
test-env/Scripts/korpress --help
|
|
112
|
+
- uses: actions/upload-artifact@v7
|
|
113
|
+
with:
|
|
114
|
+
name: wheels-windows
|
|
115
|
+
path: dist
|
|
116
|
+
|
|
117
|
+
sdist:
|
|
118
|
+
needs: check-version
|
|
119
|
+
runs-on: ubuntu-latest
|
|
120
|
+
timeout-minutes: 30
|
|
121
|
+
steps:
|
|
122
|
+
- uses: actions/checkout@v7
|
|
123
|
+
with:
|
|
124
|
+
persist-credentials: false
|
|
125
|
+
- name: Build sdist
|
|
126
|
+
uses: PyO3/maturin-action@v1
|
|
127
|
+
with:
|
|
128
|
+
command: sdist
|
|
129
|
+
args: --out dist
|
|
130
|
+
# Installing an sdist compiles it, so this needs Rust.
|
|
131
|
+
- name: Install Rust
|
|
132
|
+
uses: dtolnay/rust-toolchain@stable
|
|
133
|
+
- name: Smoke test sdist
|
|
134
|
+
run: |
|
|
135
|
+
python3 -m venv test-env
|
|
136
|
+
test-env/bin/pip install --quiet dist/*.tar.gz
|
|
137
|
+
test-env/bin/python -I -c "$SMOKE_CODE"
|
|
138
|
+
test-env/bin/korpress --help
|
|
139
|
+
- uses: actions/upload-artifact@v7
|
|
140
|
+
with:
|
|
141
|
+
name: wheels-sdist
|
|
142
|
+
path: dist
|
|
143
|
+
|
|
144
|
+
free-threaded:
|
|
145
|
+
# Wheels for free-threaded Python (3.14t): the abi3 wheels above don't
|
|
146
|
+
# cover it.
|
|
147
|
+
needs: check-version
|
|
148
|
+
runs-on: ${{ matrix.runner }}
|
|
149
|
+
timeout-minutes: 30
|
|
150
|
+
strategy:
|
|
151
|
+
matrix:
|
|
152
|
+
include:
|
|
153
|
+
- { runner: ubuntu-22.04, target: x86_64 }
|
|
154
|
+
- { runner: ubuntu-24.04-arm, target: aarch64 }
|
|
155
|
+
- { runner: macos-15-intel, target: x86_64 }
|
|
156
|
+
- { runner: macos-latest, target: aarch64 }
|
|
157
|
+
- { runner: windows-latest, target: x64 }
|
|
158
|
+
steps:
|
|
159
|
+
- uses: actions/checkout@v7
|
|
160
|
+
with:
|
|
161
|
+
persist-credentials: false
|
|
162
|
+
- uses: actions/setup-python@v7
|
|
163
|
+
id: python
|
|
164
|
+
with:
|
|
165
|
+
python-version: 3.14t
|
|
166
|
+
- name: Build wheels
|
|
167
|
+
uses: PyO3/maturin-action@v1
|
|
168
|
+
with:
|
|
169
|
+
target: ${{ matrix.target }}
|
|
170
|
+
# On Linux the build runs in a manylinux container, which has its own 3.14t.
|
|
171
|
+
args: --release --out dist -i ${{ runner.os == 'Linux' && 'python3.14t' || steps.python.outputs.python-path }}
|
|
172
|
+
manylinux: ${{ runner.os == 'Linux' && 'auto' || '' }}
|
|
173
|
+
- name: Smoke test wheel
|
|
174
|
+
shell: bash
|
|
175
|
+
run: |
|
|
176
|
+
"${{ steps.python.outputs.python-path }}" -m venv test-env
|
|
177
|
+
bin=test-env/bin; [ -d test-env/Scripts ] && bin=test-env/Scripts
|
|
178
|
+
$bin/python -m pip install --quiet dist/*.whl
|
|
179
|
+
$bin/python -I -c "$SMOKE_CODE"
|
|
180
|
+
$bin/korpress --help
|
|
181
|
+
- uses: actions/upload-artifact@v7
|
|
182
|
+
with:
|
|
183
|
+
name: wheels-free-threaded-${{ runner.os }}-${{ matrix.target }}
|
|
184
|
+
path: dist
|
|
185
|
+
|
|
186
|
+
publish:
|
|
187
|
+
name: Publish to PyPI
|
|
188
|
+
runs-on: ubuntu-latest
|
|
189
|
+
timeout-minutes: 10
|
|
190
|
+
if: startsWith(github.ref, 'refs/tags/')
|
|
191
|
+
needs: [check-version, linux, macos, windows, sdist, free-threaded]
|
|
192
|
+
environment: pypi
|
|
193
|
+
permissions:
|
|
194
|
+
id-token: write # PyPI trusted publishing
|
|
195
|
+
steps:
|
|
196
|
+
- uses: actions/download-artifact@v8
|
|
197
|
+
with:
|
|
198
|
+
path: dist
|
|
199
|
+
pattern: wheels-*
|
|
200
|
+
merge-multiple: true
|
|
201
|
+
- name: Publish to PyPI
|
|
202
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
203
|
+
with:
|
|
204
|
+
packages-dir: dist
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Working on korpress
|
|
2
|
+
|
|
3
|
+
Instructions for AI coding agents working on this repository. To use
|
|
4
|
+
korpress in a project, read `.agents/skills/korpress/SKILL.md`.
|
|
5
|
+
|
|
6
|
+
korpress is an HTML, CSS and JS minifier written in Rust, with a Python
|
|
7
|
+
bridge built with PyO3 and maturin. Read the file-by-file layout in
|
|
8
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) before changing anything.
|
|
9
|
+
|
|
10
|
+
## Setup and checks
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
uv sync # Python, the tools, and korpress built from source
|
|
14
|
+
uv run maturin develop --release # after changing Rust code, before running Python
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Before saying a change is done, run what CI runs:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
cargo fmt && cargo clippy --all-targets --features python -- -D warnings && cargo test
|
|
21
|
+
uv run ruff check . && uv run ruff format .
|
|
22
|
+
uv run pyright
|
|
23
|
+
uv run pytest
|
|
24
|
+
uv run --group docs mkdocs build --strict -d target/site # if docs or docstrings changed
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`tests/test_node.py` needs Node.js and is skipped without it. CI has it, so
|
|
28
|
+
install it before saying a JS change is done.
|
|
29
|
+
|
|
30
|
+
## Rules
|
|
31
|
+
|
|
32
|
+
- **Python 3.10 to 3.14, and free-threaded 3.14t.** CI also runs the tests on
|
|
33
|
+
3.14t with `-W error::RuntimeWarning`.
|
|
34
|
+
- **The output must never change meaning.** A minifier bug breaks a user's
|
|
35
|
+
site. When a rule is unsure, leave the input as it is. Every new rule needs
|
|
36
|
+
a test, and a JS rule also needs a differential test in `tests/test_node.py`
|
|
37
|
+
(run the original and the minified script in node, compare what they print).
|
|
38
|
+
- **No performance regression.** The three minifiers are one pass over the
|
|
39
|
+
input: no extra copy, allocation or second pass without measuring it.
|
|
40
|
+
- **Rust**: only `python.rs` uses PyO3 (behind the `python` feature). `css.rs`,
|
|
41
|
+
`html.rs`, `js.rs` and `error.rs` stay plain Rust, so `cargo test` and Rust
|
|
42
|
+
users need no Python. No dependency for parsing.
|
|
43
|
+
- **Docstrings are documentation**: the site's reference pages are built from
|
|
44
|
+
the Python docstrings and `_korpress.pyi`. Write them for users, in plain
|
|
45
|
+
English.
|
|
46
|
+
- **Keep the docs in step**: the guide in `docs/`, the README when a headline
|
|
47
|
+
changes, and the skill when something it shows changes. The skill has two
|
|
48
|
+
copies that must stay identical: `.agents/skills/korpress/SKILL.md` and
|
|
49
|
+
`python/korpress/_skill/SKILL.md` (check with `cmp`).
|
|
50
|
+
- **Before 1.0, break the API directly**: no deprecation shims. Every change
|
|
51
|
+
goes in `CHANGELOG.md` under `## Unreleased`, with how to update.
|
|
52
|
+
- Code, comments, docs and commit messages are in English. Commits follow
|
|
53
|
+
Conventional Commits (`feat:`, `fix:`, `docs:`, `perf:`...).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0a1
|
|
4
|
+
|
|
5
|
+
First alpha: HTML, CSS and JS minifiers, a Python API, a command line and a Rust core.
|
|
6
|
+
|
|
7
|
+
- CSS minifier: comments, whitespace, empty rules, the last `;`, numbers (`0.50` to `.5`, `0px` to `0`, not inside `calc()`, `var()` fallbacks or `flex`), hex colors, quotes in `url()`, native nesting. Custom properties are left alone.
|
|
8
|
+
- JS minifier, token based, with no renaming and no dead code removal: comments, whitespace and useless `;` before `}`. Line breaks that automatic semicolon insertion needs are kept, regular expressions are told apart from divisions, `${...}` in template literals is scanned like code, and `/*!`, `@license` and `@preserve` comments are kept. Broken input (an unterminated string, comment, template or regular expression) raises `korpress.KorpressError`, a `ValueError` with `.line` and `.column`.
|
|
9
|
+
- HTML minifier: whitespace collapsed like a browser does, comments, attribute quotes, boolean attributes, redundant `type="text/javascript"`, and inline `<style>`, `<script>`, `style=""` and JSON scripts. `<pre>`, `<textarea>`, svg text and conditional comments are left alone. A script that cannot be minified is left as it was.
|
|
10
|
+
- Python API: `minify_html`, `minify_css`, `minify_js`, `minify` and `minify_file`, with keyword options such as `keep_important_comments` and `collapse_whitespace`.
|
|
11
|
+
- `korpress` command line: a file, a whole tree with `-o`, `--copy` for the other files, `-i` for in place, and `-t` for standard input. Files named `*.min.*`, hidden directories and `node_modules` are skipped.
|
|
12
|
+
- Rust core with no Python and no dependency: `_korpress::css`, `_korpress::js` and `_korpress::html`.
|
|
13
|
+
- Python 3.10 or later. Wheels for Linux, macOS, Windows and free-threaded 3.14t.
|
|
14
|
+
- Documentation site (MkDocs): tutorial, guide, command line, Korvex page, glossary, API reference and an AI page with `llms.txt`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|