Skip to content

Commit 0fd46d0

Browse files
authored
chore: Update python bindings
* chore(python): Update `PyO3` to `0.19.0` * chore(python): Update benchmark * chore(python): Update `maturin` * chore(python): Update `maturin`
1 parent ef14028 commit 0fd46d0

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

bindings/python/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- Update `PyO3` to `0.19.0`.
8+
59
### Performance
610

711
- 15-30% average performance improvement due switch from `kuchiki` to a custom-built HTML tree representation.

bindings/python/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "css_inline"
1010
crate-type = ["cdylib"]
1111

1212
[build-dependencies]
13-
built = { version = "0.5", features = ["chrono"] }
13+
built = { version = "0.6", features = ["chrono"] }
1414

1515
[dependencies.css-inline]
1616
path = "../../css-inline"
@@ -21,7 +21,7 @@ features = ["http", "file"]
2121
[dependencies]
2222
url = "2"
2323
rayon = "1"
24-
pyo3 = { version = "0.18.0", features = ["extension-module", "abi3-py37"] }
24+
pyo3 = { version = "0.19.0", features = ["extension-module", "abi3-py37"] }
2525
pyo3-built = "0.4"
2626

2727
[profile.release]

bindings/python/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,30 @@ library has excellent performance characteristics. In comparison with other Pyth
144144

145145
For inlining CSS in the html document from the `Usage` section above there is the following breakdown in the benchmarks:
146146

147-
- `css_inline 0.8.2` - 22.42 us
148-
- `premailer 3.10.0` - 332.02 us (**x14.81**)
149-
- `toronado 0.1.0` - 1.59 ms (**x71.17**)
150-
- `inlinestyler 0.2.5` - 2.35 ms (**x105.07**)
151-
- `pynliner 0.8.0` - 2.79 ms (**x124.80**)
147+
- `css_inline 0.9.0` - 16.31 us
148+
- `premailer 3.10.0` - 302.01 us (**x18.51**)
149+
- `toronado 0.1.0` - 1.42 ms (**x87.06**)
150+
- `inlinestyler 0.2.5` - 2.06 ms (**x126.30**)
151+
- `pynliner 0.8.0` - 2.46 ms (**x150.82**)
152152

153153
Realistic email 1:
154154

155-
- `css_inline 0.8.2` - 487.75 us
156-
- `premailer 3.10.0` - 3.92 ms (**x8.05**)
157-
- `toronado 0.1.0` - 52.09 ms (**x106.81**)
158-
- `inlinestyler 0.2.5` - 81.17 ms (**x166.43**)
159-
- `pynliner 0.8.0` - 128.81 ms (**x264.1**)
155+
- `css_inline 0.9.0` - 393.79 us
156+
- `premailer 3.10.0` - 2.72 ms (**x6.90**)
157+
- `toronado 0.1.0` - 30.55 ms (**x77.57**)
158+
- `inlinestyler 0.2.5` - 51.69 ms (**x141.42**)
159+
- `pynliner 0.8.0` - 99.95 ms (**x253.81**)
160160

161161
Realistic email 2:
162162

163-
- `css_inline 0.8.2` - 386.64 us
164-
- `premailer 3.10.0` - 4.82 ms (**x12.47**)
163+
- `css_inline 0.9.0` - 296.61 us
164+
- `premailer 3.10.0` - 4.07 ms (**x13.72**)
165165
- `toronado 0.1.0` - `Error: Pseudo-elements are not supported`
166-
- `inlinestyler 0.2.5` - 40.80 ms (**x105.54**)
166+
- `inlinestyler 0.2.5` - 33.31 ms (**x112.30**)
167167
- `pynliner 0.8.0` - `Error: No match was found`
168168

169169
You can take a look at the benchmarks' code at `benches/bench.py` file.
170-
The results above were measured with stable `rustc 1.64.0`, `Python 3.10.4`, `Linux x86_64` on i8700K, and 32GB RAM.
170+
The results above were measured with stable `rustc 1.69.0`, `Python 3.11.0`, `Linux x86_64` on i8700K, and 32GB RAM.
171171

172172
## Comparison with other libraries
173173

bindings/python/css_inline.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class CSSInliner:
66
base_url: str | None = None,
77
load_remote_stylesheets: bool = True,
88
extra_css: str | None = None,
9+
preallocate_node_capacity: int | None = None,
910
) -> None: ...
1011
def inline(self, html: str) -> str: ...
1112
def inline_many(self, html: list[str]) -> list[str]: ...
@@ -17,14 +18,17 @@ def inline(
1718
base_url: str | None = None,
1819
load_remote_stylesheets: bool = True,
1920
extra_css: str | None = None,
21+
preallocate_node_capacity: int | None = None,
2022
) -> str: ...
23+
2124
def inline_many(
2225
html: list[str],
2326
inline_style_tags: bool = True,
2427
remove_style_tags: bool = False,
2528
base_url: str | None = None,
2629
load_remote_stylesheets: bool = True,
2730
extra_css: str | None = None,
31+
preallocate_node_capacity: int | None = None,
2832
) -> list[str]: ...
2933

3034
class InlineError(ValueError): ...

bindings/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ homepage = "https://github.com/Stranger6667/css-inline/tree/master/bindings/pyth
4343
repository = "https://github.com/Stranger6667/css-inline"
4444

4545
[build-system]
46-
requires = ["maturin>=0.14,<0.15"]
46+
requires = ["maturin>=1.1"]
4747
build-backend = "maturin"
4848

4949
[tool.maturin]

bindings/python/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ fn parse_url(url: Option<String>) -> PyResult<Option<url::Url>> {
7171
///
7272
/// Customizable CSS inliner.
7373
#[pyclass]
74-
#[pyo3(
75-
text_signature = "(inline_style_tags=True, remove_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=0)"
76-
)]
7774
struct CSSInliner {
7875
inner: rust_inline::CSSInliner<'static>,
7976
}
8077

8178
#[pymethods]
8279
impl CSSInliner {
83-
#[new]
80+
#[new(
81+
text_signature = "(inline_style_tags=True, remove_style_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=0)"
82+
)]
8483
fn new(
8584
inline_style_tags: Option<bool>,
8685
remove_style_tags: Option<bool>,

0 commit comments

Comments
 (0)