diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 615cd3e8..b3d9264b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -456,6 +456,27 @@ jobs: run: tox -e py working-directory: ./bindings/python + build-pyodide: + name: Build PyOdide wheel + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + toolchain: nightly + targets: wasm32-unknown-emscripten + - uses: actions/setup-python@v5 + with: + python-version: 3.12 + - run: | + pip install pyodide-build>=0.28.0 + echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV + - uses: mymindstorm/setup-emsdk@v14 + with: + version: ${{ env.EMSCRIPTEN_VERSION }} + - run: pyodide build + working-directory: ./bindings/python + test-ruby: strategy: fail-fast: false diff --git a/bindings/python/CHANGELOG.md b/bindings/python/CHANGELOG.md index 86011515..2892442c 100644 --- a/bindings/python/CHANGELOG.md +++ b/bindings/python/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Added + +- Support & build for PyOdide. [#411](https://github.com/Stranger6667/css-inline/pull/411) + ### Changed - Bump MSRV to `1.71.1`. diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index e286df51..8649e06d 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -19,7 +19,13 @@ pyo3-built = "0.5" rayon = "1" url = "2" -[dependencies.css-inline] +[target.'cfg(target_arch = "wasm32")'.dependencies.css-inline] +path = "../../css-inline" +version = "*" +default-features = false +features = ["stylesheet-cache"] + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.css-inline] path = "../../css-inline" version = "*" default-features = false diff --git a/bindings/python/README.md b/bindings/python/README.md index d185df37..d6cc3539 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -42,7 +42,7 @@ into: - Resolves external stylesheets (including local files) - Optionally caches external stylesheets - Can process multiple documents in parallel -- Works on Linux, Windows, and macOS +- Works on Linux, Windows, macOS and in the browser via PyOdide - Supports HTML5 & CSS3 - Tested on CPython 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 and PyPy 3.7, 3.8, 3.9, 3.10. diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 743dac5b..e2430778 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -41,6 +41,7 @@ impl From for PyErr { fn from(error: InlineErrorWrapper) -> Self { match error.0 { rust_inline::InlineError::IO(error) => InlineError::new_err(error.to_string()), + #[cfg(not(target_arch = "wasm32"))] rust_inline::InlineError::Network { .. } => InlineError::new_err(error.0.to_string()), rust_inline::InlineError::ParseError(message) => { InlineError::new_err(message.to_string())