Skip to content

Commit 2da2f78

Browse files
committed
feat(python): Add support for PyOdide
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent e605243 commit 2da2f78

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

.github/workflows/build.yml

+21
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,27 @@ jobs:
456456
run: tox -e py
457457
working-directory: ./bindings/python
458458

459+
build-pyodide:
460+
name: Build PyOdide wheel
461+
runs-on: ubuntu-22.04
462+
steps:
463+
- uses: actions/checkout@v4
464+
- uses: dtolnay/rust-toolchain@nightly
465+
with:
466+
toolchain: nightly
467+
targets: wasm32-unknown-emscripten
468+
- uses: actions/setup-python@v5
469+
with:
470+
python-version: 3.12
471+
- run: |
472+
pip install pyodide-build>=0.28.0
473+
echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV
474+
- uses: mymindstorm/setup-emsdk@v14
475+
with:
476+
version: ${{ env.EMSCRIPTEN_VERSION }}
477+
- run: pyodide build
478+
working-directory: ./bindings/python
479+
459480
test-ruby:
460481
strategy:
461482
fail-fast: false

bindings/python/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Support & build for PyOdide. [#411](https://github.com/Stranger6667/css-inline/pull/411)
8+
59
### Changed
610

711
- Bump MSRV to `1.71.1`.

bindings/python/Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ pyo3-built = "0.5"
1919
rayon = "1"
2020
url = "2"
2121

22-
[dependencies.css-inline]
22+
[target.'cfg(target_arch = "wasm32")'.dependencies.css-inline]
23+
path = "../../css-inline"
24+
version = "*"
25+
default-features = false
26+
features = ["stylesheet-cache"]
27+
28+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.css-inline]
2329
path = "../../css-inline"
2430
version = "*"
2531
default-features = false

bindings/python/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ into:
4242
- Resolves external stylesheets (including local files)
4343
- Optionally caches external stylesheets
4444
- Can process multiple documents in parallel
45-
- Works on Linux, Windows, and macOS
45+
- Works on Linux, Windows, macOS and in the browser via PyOdide
4646
- Supports HTML5 & CSS3
4747
- 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.
4848

bindings/python/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl From<InlineErrorWrapper> for PyErr {
4141
fn from(error: InlineErrorWrapper) -> Self {
4242
match error.0 {
4343
rust_inline::InlineError::IO(error) => InlineError::new_err(error.to_string()),
44+
#[cfg(not(target_arch = "wasm32"))]
4445
rust_inline::InlineError::Network { .. } => InlineError::new_err(error.0.to_string()),
4546
rust_inline::InlineError::ParseError(message) => {
4647
InlineError::new_err(message.to_string())

0 commit comments

Comments
 (0)