Skip to content

Commit

Permalink
feat(python): Add support for PyOdide
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Dec 27, 2024
1 parent e605243 commit 2da2f78
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
8 changes: 7 additions & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl From<InlineErrorWrapper> 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())
Expand Down

0 comments on commit 2da2f78

Please sign in to comment.