Fix Python module name

This commit is contained in:
Wilson Lin 2021-04-07 20:50:05 +10:00
parent b4142be729
commit 7b1ac85f88
4 changed files with 17 additions and 2 deletions

View File

@ -46,7 +46,7 @@ jobs:
- name: Build native module
working-directory: ./python
run: |
cp Cargo.${{ matrix.feature }}.toml Cargo.toml
python prepare.py ${{ matrix.feature }}
cargo build --release
- name: Install Python build tools (macOS)

1
python/.gitignore vendored
View File

@ -1,5 +1,6 @@
/Cargo.lock
/Cargo.toml
/src/lib.rs
/target/
__pycache__/

14
python/prepare.py Normal file
View File

@ -0,0 +1,14 @@
import shutil
import sys
feature = sys.argv[1]
module_name = "minify_html_core" if feature == "core" else "minify_html"
cargo_file = "Cargo.core.toml" if feature == "core" else "Cargo.js.toml"
with open("src/lib.template.rs", "r") as template:
actual = template.read().replace("REPLACE_WITH_MODULE_NAME", module_name)
with open("src/lib.rs", "w") as librs:
librs.write(actual)
shutil.copyfile(cargo_file, "Cargo.toml")

View File

@ -17,7 +17,7 @@ fn minify(code: String, minify_js: bool, minify_css: bool) -> PyResult<String> {
}
#[pymodule]
fn minify_html(_py: Python, m: &PyModule) -> PyResult<()> {
fn REPLACE_WITH_MODULE_NAME(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(minify))?;
Ok(())