Create onepass variant for Python
This commit is contained in:
parent
fde8354461
commit
776539b9ce
|
@ -11,6 +11,7 @@ jobs:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
variant: [main, onepass]
|
||||||
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
|
os: [macos-11.0, ubuntu-18.04, windows-2019, self-hosted-linux-arm64, self-hosted-macos-arm64]
|
||||||
python: [3.8, 3.9, '3.10']
|
python: [3.8, 3.9, '3.10']
|
||||||
steps:
|
steps:
|
||||||
|
@ -49,7 +50,7 @@ jobs:
|
||||||
run: bash ./prebuild.sh
|
run: bash ./prebuild.sh
|
||||||
|
|
||||||
- name: Build native module
|
- name: Build native module
|
||||||
working-directory: ./python
|
working-directory: ./python/${{ matrix.feature }}
|
||||||
run: cargo build --release
|
run: cargo build --release
|
||||||
|
|
||||||
- name: Install Python build tools (macOS x64)
|
- name: Install Python build tools (macOS x64)
|
||||||
|
@ -71,7 +72,7 @@ jobs:
|
||||||
|
|
||||||
- name: Pack and publish package
|
- name: Pack and publish package
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: ./python
|
working-directory: ./python/${{ matrix.feature }}
|
||||||
run: |
|
run: |
|
||||||
cat << 'EOF' > "$HOME/.pypirc"
|
cat << 'EOF' > "$HOME/.pypirc"
|
||||||
[pypi]
|
[pypi]
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
## 0.9.2
|
## 0.9.2
|
||||||
|
|
||||||
- Fix Node.js dependency version.
|
- Fix Node.js dependency version.
|
||||||
|
- Create onepass variant for Python.
|
||||||
|
|
||||||
## 0.9.1
|
## 0.9.1
|
||||||
|
|
||||||
|
|
5
format
5
format
|
@ -4,7 +4,7 @@ set -Eeuxo pipefail
|
||||||
|
|
||||||
pushd "$(dirname "$0")" >/dev/null
|
pushd "$(dirname "$0")" >/dev/null
|
||||||
|
|
||||||
npx prettier@2.3.2 -w 'version' 'bench/*.{js,json}' 'bench/runners/*.{js,json}' 'bench/runners/*/*.{js,json}' 'gen/*.{ts,json}'
|
npx prettier@2.3.2 -w 'version' 'bench/*.{js,json}' 'bench/runners/*.{js,json}' 'bench/runners/*/*.{js,json}' 'gen/*.{ts,json}' 'nodejs/*.{js,json,ts}'
|
||||||
|
|
||||||
for dir in \
|
for dir in \
|
||||||
bench/runners/minify-html \
|
bench/runners/minify-html \
|
||||||
|
@ -16,7 +16,8 @@ for dir in \
|
||||||
fuzz/process \
|
fuzz/process \
|
||||||
java \
|
java \
|
||||||
nodejs \
|
nodejs \
|
||||||
python \
|
python/main \
|
||||||
|
python/onepass \
|
||||||
ruby \
|
ruby \
|
||||||
rust/main \
|
rust/main \
|
||||||
rust/onepass \
|
rust/onepass \
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../README.md
|
|
|
@ -15,7 +15,7 @@ name = "minify_html"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
minify-html = { path = "../rust/main" }
|
minify-html = { path = "../../rust/main" }
|
||||||
[dependencies.pyo3]
|
[dependencies.pyo3]
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
features = ["extension-module"]
|
features = ["extension-module"]
|
|
@ -0,0 +1 @@
|
||||||
|
../../README.md
|
|
@ -0,0 +1,11 @@
|
||||||
|
[target.x86_64-apple-darwin]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-undefined",
|
||||||
|
"-C", "link-arg=dynamic_lookup",
|
||||||
|
]
|
||||||
|
|
||||||
|
[target.aarch64-apple-darwin]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-undefined",
|
||||||
|
"-C", "link-arg=dynamic_lookup",
|
||||||
|
]
|
|
@ -0,0 +1,10 @@
|
||||||
|
/Cargo.lock
|
||||||
|
/target/
|
||||||
|
|
||||||
|
__pycache__/
|
||||||
|
/venv/
|
||||||
|
|
||||||
|
# Used by Python setuptools.
|
||||||
|
/build/
|
||||||
|
/dist/
|
||||||
|
/*.egg-info/
|
|
@ -0,0 +1,21 @@
|
||||||
|
[package]
|
||||||
|
publish = false
|
||||||
|
name = "minify_html_onepass"
|
||||||
|
description = "Even faster version of minify-html"
|
||||||
|
license = "MIT"
|
||||||
|
homepage = "https://github.com/wilsonzlin/minify-html"
|
||||||
|
readme = "README.md"
|
||||||
|
repository = "https://github.com/wilsonzlin/minify-html.git"
|
||||||
|
version = "0.9.1"
|
||||||
|
authors = ["Wilson Lin <code@wilsonl.in>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "minify_html_onepass"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
minify-html-onepass = { path = "../../rust/onepass" }
|
||||||
|
[dependencies.pyo3]
|
||||||
|
version = "0.13.0"
|
||||||
|
features = ["extension-module"]
|
|
@ -0,0 +1 @@
|
||||||
|
../../rust/onepass/README.md
|
|
@ -0,0 +1,5 @@
|
||||||
|
def minify(
|
||||||
|
code: str,
|
||||||
|
minify_css: bool = False,
|
||||||
|
minify_js: bool = False,
|
||||||
|
) -> str: ...
|
|
@ -0,0 +1,24 @@
|
||||||
|
use minify_html_onepass::{Cfg, Error, in_place as minify_html_native};
|
||||||
|
use pyo3::prelude::*;
|
||||||
|
use pyo3::exceptions::PySyntaxError;
|
||||||
|
use pyo3::wrap_pyfunction;
|
||||||
|
use std::str::from_utf8_unchecked;
|
||||||
|
|
||||||
|
#[pyfunction(py_args="*", minify_js="false", minify_css="false")]
|
||||||
|
fn minify(code: String, minify_js: bool, minify_css: bool) -> PyResult<String> {
|
||||||
|
let mut code = code.into_bytes();
|
||||||
|
match minify_html_native(&mut code, &Cfg {
|
||||||
|
minify_js,
|
||||||
|
minify_css,
|
||||||
|
}) {
|
||||||
|
Ok(out_len) => Ok(unsafe { from_utf8_unchecked(&code[0..out_len]).to_string() }),
|
||||||
|
Err(Error { error_type, position }) => Err(PySyntaxError::new_err(format!("{} [Character {}]", error_type.message(), position))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pymodule]
|
||||||
|
fn minify_html_onepass(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
|
m.add_wrapped(wrap_pyfunction!(minify))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -14,12 +14,11 @@ An HTML minifier that provides the functionality of [minify-html](https://github
|
||||||
|
|
||||||
The API is different compared to minify-html; refer to per-package documentation for more details.
|
The API is different compared to minify-html; refer to per-package documentation for more details.
|
||||||
|
|
||||||
- <img width="24" src="https://wilsonl.in/minify-html/icon/java.png"> [in.wilsonl.minifyhtmlonepass](https://search.maven.org/artifact/in.wilsonl.minifyhtmlonepass/minify-html-onepass)
|
|
||||||
- <img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png"> [@minify-html/onepass](https://www.npmjs.com/package/@minify-html/onepass)
|
|
||||||
- <img width="24" src="https://wilsonl.in/minify-html/icon/python.png"> [minify-html-onepass](https://pypi.org/project/minify-html-onepass)
|
- <img width="24" src="https://wilsonl.in/minify-html/icon/python.png"> [minify-html-onepass](https://pypi.org/project/minify-html-onepass)
|
||||||
- <img width="24" src="https://wilsonl.in/minify-html/icon/ruby.png"> [minify_html_onepass](https://rubygems.org/gems/minify_html_onepass)
|
|
||||||
- <img width="24" src="https://wilsonl.in/minify-html/icon/rust.png"> [minify-html-onepass](https://crates.io/crates/minify-html-onepass)
|
- <img width="24" src="https://wilsonl.in/minify-html/icon/rust.png"> [minify-html-onepass](https://crates.io/crates/minify-html-onepass)
|
||||||
|
|
||||||
|
If you don't see your preferred language here and the main library supports it, raise an issue.
|
||||||
|
|
||||||
## Parsing
|
## Parsing
|
||||||
|
|
||||||
In addition to the [minify-html rules](https://github.com/wilsonzlin/minify-html/blob/master/notes/Parsing.md), the onepass variant has additional requirements:
|
In addition to the [minify-html rules](https://github.com/wilsonzlin/minify-html/blob/master/notes/Parsing.md), the onepass variant has additional requirements:
|
||||||
|
|
3
version
3
version
|
@ -101,7 +101,8 @@ for (const f of [
|
||||||
"cli/Cargo.toml",
|
"cli/Cargo.toml",
|
||||||
"nodejs/Cargo.toml",
|
"nodejs/Cargo.toml",
|
||||||
"java/Cargo.toml",
|
"java/Cargo.toml",
|
||||||
"python/Cargo.toml",
|
"python/main/Cargo.toml",
|
||||||
|
"python/onepass/Cargo.toml",
|
||||||
"ruby/Cargo.toml",
|
"ruby/Cargo.toml",
|
||||||
"wasm/Cargo.toml",
|
"wasm/Cargo.toml",
|
||||||
]) {
|
]) {
|
||||||
|
|
Loading…
Reference in New Issue