diff options
author | CoprDistGit <infra@openeuler.org> | 2023-04-11 20:42:22 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-04-11 20:42:22 +0000 |
commit | 0a3b93a618bbd7401bd29b72410ae7aac4619683 (patch) | |
tree | f4dc103da2f67ce48c94ac81f7830bccf8bedc04 | |
parent | c07aef5343395a0cdc11583ee1f26a2b755638ee (diff) |
automatic import of python-css-inline
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-css-inline.spec | 668 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 670 insertions, 0 deletions
@@ -0,0 +1 @@ +/css_inline-0.8.7.tar.gz diff --git a/python-css-inline.spec b/python-css-inline.spec new file mode 100644 index 0000000..e60317e --- /dev/null +++ b/python-css-inline.spec @@ -0,0 +1,668 @@ +%global _empty_manifest_terminate_build 0 +Name: python-css-inline +Version: 0.8.7 +Release: 1 +Summary: Fast CSS inlining written in Rust +License: MIT +URL: https://pypi.org/project/css-inline/ +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/53/4d/511e3155bf8f863d129e8d1006cc01f26ecfb36b2622dd32551c654c5f66/css_inline-0.8.7.tar.gz + + +%description +# css_inline + +[](https://github.com/Stranger6667/css-inline/actions) +[](https://pypi.org/project/css_inline/) +[](https://pypi.org/project/css_inline/) +[](https://opensource.org/licenses/MIT) + +Blazing-fast CSS inlining for Python implemented with Mozilla's Servo project components. + +Features: + +- Removing `style` tags after inlining; +- Resolving external stylesheets (including local files); +- Control if `style` tags should be processed; +- Out-of-document CSS to inline; +- Inlining multiple documents in parallel (via Rust-level threads) + +The project supports CSS Syntax Level 3. + +## Installation + +To install `css_inline` via `pip` run the following command: + +``` +pip install css_inline +``` + +Pre-compiled wheels for most popular platforms are provided. If your platform is not in the support table below, you will need +a Rust compiler to build this package from source. The minimum supported Rust version is 1.60. + +## Usage + +To inline CSS in a HTML document: + +```python +import css_inline + +HTML = """<html> +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html>""" + +inlined = css_inline.inline(HTML) +# HTML becomes this: +# +# <html> +# <head> +# <title>Test</title> +# <style>h1 { color:blue; }</style> +# </head> +# <body> +# <h1 style="color:blue;">Big Text</h1> +# </body> +# </html> +``` + +If you want to inline many HTML documents, you can utilize `inline_many` that processes the input in parallel. + +```python +import css_inline + +css_inline.inline_many(["<...>", "<...>"]) +``` + +`inline_many` will spawn threads on the Rust level; thus, you can expect it's running faster than `css_inline.inline` via Python's `multiprocessing` or `threading` modules. + +For customization options use the `CSSInliner` class: + +```python +import css_inline + +inliner = css_inline.CSSInliner(remove_style_tags=True) +inliner.inline("...") +``` + +If you'd like to skip CSS inlining for an HTML tag, add `data-css-inline="ignore"` attribute to it: + +```html +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <!-- The tag below won't receive additional styles --> + <h1 data-css-inline="ignore">Big Text</h1> +</body> +</html> +``` + +This attribute also allows you to skip `link` and `style` tags: + +```html +<head> + <title>Test</title> + <!-- Styles below are ignored --> + <style data-css-inline="ignore">h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html> +``` + +If you'd like to load stylesheets from your filesystem, use the `file://` scheme: + +```python +import css_inline + +# styles/email is relative to the current directory +inliner = css_inline.CSSInliner(base_url="file://styles/email/") +inliner.inline("...") +``` + +## Standards support & restrictions + +`css-inline` is built on top of [kuchiki](https://crates.io/crates/kuchiki) and [cssparser](https://crates.io/crates/cssparser) and relies on their behavior for HTML / CSS parsing and serialization. +Notably: + +- Only HTML 5, XHTML is not supported; +- Only CSS 3; +- Only UTF-8 for string representation. Other document encodings are not yet supported. + +If you'd like to work around some XHTML compatibility issues like closing empty tags (`<hr>` vs. `<hr/>`), you can use the following snippet that involves `lxml`: + +```python +import css_inline +from lxml import html, etree + +document = "..." # Your HTML document +inlined = css_inline.inline(document) +tree = html.fromstring(inlined) +inlined = etree.tostring(tree).decode(encoding="utf-8") +``` + +## Performance + +Due to the usage of efficient tooling from Mozilla's Servo project (`html5ever`, `rust-cssparser` and others) this +library has excellent performance characteristics. In comparison with other Python projects, it is usually >10x faster than the nearest alternative. + +For inlining CSS in the html document from the `Usage` section above there is the following breakdown in the benchmarks: + +- `css_inline 0.8.2` - 22.42 us +- `premailer 3.10.0` - 332.02 us (**x14.81**) +- `toronado 0.1.0` - 1.59 ms (**x71.17**) +- `inlinestyler 0.2.5` - 2.35 ms (**x105.07**) +- `pynliner 0.8.0` - 2.79 ms (**x124.80**) + +Realistic email 1: + +- `css_inline 0.8.2` - 487.75 us +- `premailer 3.10.0` - 3.92 ms (**x8.05**) +- `toronado 0.1.0` - 52.09 ms (**x106.81**) +- `inlinestyler 0.2.5` - 81.17 ms (**x166.43**) +- `pynliner 0.8.0` - 128.81 ms (**x264.1**) + +Realistic email 2: + +- `css_inline 0.8.2` - 386.64 us +- `premailer 3.10.0` - 4.82 ms (**x12.47**) +- `toronado 0.1.0` - `Error: Pseudo-elements are not supported` +- `inlinestyler 0.2.5` - 40.80 ms (**x105.54**) +- `pynliner 0.8.0` - `Error: No match was found` + +You can take a look at the benchmarks' code at `benches/bench.py` file. +The results above were measured with stable `rustc 1.64.0`, `Python 3.10.4`, `Linux x86_64` on i8700K, and 32GB RAM. + +## Comparison with other libraries + +Besides performance, `css-inline` differs from other Python libraries for CSS inlining. + +- Generally supports more CSS features than other libraries (for example, `toronado` and `pynliner` do not support pseudo-elements); +- It has fewer configuration options and not as flexible as `premailer`; +- Works on fewer platforms than LXML-based libraries (`premailer`, `inlinestyler`, `toronado`, and optionally `pynliner`); +- Does not have debug logs yet; +- Supports only HTML 5. + +## Python support + +`css_inline` supports CPython 3.7, 3.8, 3.9, 3.10, 3.11 and PyPy 3.7, 3.8, 3.9. + +## Extra materials + +If you want to know how this library was created & how it works internally, you could take a look at these articles: + +- [Rust crate](https://dygalo.dev/blog/rust-for-a-pythonista-2/) +- [Python bindings](https://dygalo.dev/blog/rust-for-a-pythonista-3/) + +## License + +The code in this project is licensed under [MIT license](https://opensource.org/licenses/MIT). +By contributing to `css_inline`, you agree that your contributions +will be licensed under its MIT license. + + + +%package -n python3-css-inline +Summary: Fast CSS inlining written in Rust +Provides: python-css-inline +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +BuildRequires: python3-cffi +BuildRequires: gcc +BuildRequires: gdb +%description -n python3-css-inline +# css_inline + +[](https://github.com/Stranger6667/css-inline/actions) +[](https://pypi.org/project/css_inline/) +[](https://pypi.org/project/css_inline/) +[](https://opensource.org/licenses/MIT) + +Blazing-fast CSS inlining for Python implemented with Mozilla's Servo project components. + +Features: + +- Removing `style` tags after inlining; +- Resolving external stylesheets (including local files); +- Control if `style` tags should be processed; +- Out-of-document CSS to inline; +- Inlining multiple documents in parallel (via Rust-level threads) + +The project supports CSS Syntax Level 3. + +## Installation + +To install `css_inline` via `pip` run the following command: + +``` +pip install css_inline +``` + +Pre-compiled wheels for most popular platforms are provided. If your platform is not in the support table below, you will need +a Rust compiler to build this package from source. The minimum supported Rust version is 1.60. + +## Usage + +To inline CSS in a HTML document: + +```python +import css_inline + +HTML = """<html> +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html>""" + +inlined = css_inline.inline(HTML) +# HTML becomes this: +# +# <html> +# <head> +# <title>Test</title> +# <style>h1 { color:blue; }</style> +# </head> +# <body> +# <h1 style="color:blue;">Big Text</h1> +# </body> +# </html> +``` + +If you want to inline many HTML documents, you can utilize `inline_many` that processes the input in parallel. + +```python +import css_inline + +css_inline.inline_many(["<...>", "<...>"]) +``` + +`inline_many` will spawn threads on the Rust level; thus, you can expect it's running faster than `css_inline.inline` via Python's `multiprocessing` or `threading` modules. + +For customization options use the `CSSInliner` class: + +```python +import css_inline + +inliner = css_inline.CSSInliner(remove_style_tags=True) +inliner.inline("...") +``` + +If you'd like to skip CSS inlining for an HTML tag, add `data-css-inline="ignore"` attribute to it: + +```html +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <!-- The tag below won't receive additional styles --> + <h1 data-css-inline="ignore">Big Text</h1> +</body> +</html> +``` + +This attribute also allows you to skip `link` and `style` tags: + +```html +<head> + <title>Test</title> + <!-- Styles below are ignored --> + <style data-css-inline="ignore">h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html> +``` + +If you'd like to load stylesheets from your filesystem, use the `file://` scheme: + +```python +import css_inline + +# styles/email is relative to the current directory +inliner = css_inline.CSSInliner(base_url="file://styles/email/") +inliner.inline("...") +``` + +## Standards support & restrictions + +`css-inline` is built on top of [kuchiki](https://crates.io/crates/kuchiki) and [cssparser](https://crates.io/crates/cssparser) and relies on their behavior for HTML / CSS parsing and serialization. +Notably: + +- Only HTML 5, XHTML is not supported; +- Only CSS 3; +- Only UTF-8 for string representation. Other document encodings are not yet supported. + +If you'd like to work around some XHTML compatibility issues like closing empty tags (`<hr>` vs. `<hr/>`), you can use the following snippet that involves `lxml`: + +```python +import css_inline +from lxml import html, etree + +document = "..." # Your HTML document +inlined = css_inline.inline(document) +tree = html.fromstring(inlined) +inlined = etree.tostring(tree).decode(encoding="utf-8") +``` + +## Performance + +Due to the usage of efficient tooling from Mozilla's Servo project (`html5ever`, `rust-cssparser` and others) this +library has excellent performance characteristics. In comparison with other Python projects, it is usually >10x faster than the nearest alternative. + +For inlining CSS in the html document from the `Usage` section above there is the following breakdown in the benchmarks: + +- `css_inline 0.8.2` - 22.42 us +- `premailer 3.10.0` - 332.02 us (**x14.81**) +- `toronado 0.1.0` - 1.59 ms (**x71.17**) +- `inlinestyler 0.2.5` - 2.35 ms (**x105.07**) +- `pynliner 0.8.0` - 2.79 ms (**x124.80**) + +Realistic email 1: + +- `css_inline 0.8.2` - 487.75 us +- `premailer 3.10.0` - 3.92 ms (**x8.05**) +- `toronado 0.1.0` - 52.09 ms (**x106.81**) +- `inlinestyler 0.2.5` - 81.17 ms (**x166.43**) +- `pynliner 0.8.0` - 128.81 ms (**x264.1**) + +Realistic email 2: + +- `css_inline 0.8.2` - 386.64 us +- `premailer 3.10.0` - 4.82 ms (**x12.47**) +- `toronado 0.1.0` - `Error: Pseudo-elements are not supported` +- `inlinestyler 0.2.5` - 40.80 ms (**x105.54**) +- `pynliner 0.8.0` - `Error: No match was found` + +You can take a look at the benchmarks' code at `benches/bench.py` file. +The results above were measured with stable `rustc 1.64.0`, `Python 3.10.4`, `Linux x86_64` on i8700K, and 32GB RAM. + +## Comparison with other libraries + +Besides performance, `css-inline` differs from other Python libraries for CSS inlining. + +- Generally supports more CSS features than other libraries (for example, `toronado` and `pynliner` do not support pseudo-elements); +- It has fewer configuration options and not as flexible as `premailer`; +- Works on fewer platforms than LXML-based libraries (`premailer`, `inlinestyler`, `toronado`, and optionally `pynliner`); +- Does not have debug logs yet; +- Supports only HTML 5. + +## Python support + +`css_inline` supports CPython 3.7, 3.8, 3.9, 3.10, 3.11 and PyPy 3.7, 3.8, 3.9. + +## Extra materials + +If you want to know how this library was created & how it works internally, you could take a look at these articles: + +- [Rust crate](https://dygalo.dev/blog/rust-for-a-pythonista-2/) +- [Python bindings](https://dygalo.dev/blog/rust-for-a-pythonista-3/) + +## License + +The code in this project is licensed under [MIT license](https://opensource.org/licenses/MIT). +By contributing to `css_inline`, you agree that your contributions +will be licensed under its MIT license. + + + +%package help +Summary: Development documents and examples for css-inline +Provides: python3-css-inline-doc +%description help +# css_inline + +[](https://github.com/Stranger6667/css-inline/actions) +[](https://pypi.org/project/css_inline/) +[](https://pypi.org/project/css_inline/) +[](https://opensource.org/licenses/MIT) + +Blazing-fast CSS inlining for Python implemented with Mozilla's Servo project components. + +Features: + +- Removing `style` tags after inlining; +- Resolving external stylesheets (including local files); +- Control if `style` tags should be processed; +- Out-of-document CSS to inline; +- Inlining multiple documents in parallel (via Rust-level threads) + +The project supports CSS Syntax Level 3. + +## Installation + +To install `css_inline` via `pip` run the following command: + +``` +pip install css_inline +``` + +Pre-compiled wheels for most popular platforms are provided. If your platform is not in the support table below, you will need +a Rust compiler to build this package from source. The minimum supported Rust version is 1.60. + +## Usage + +To inline CSS in a HTML document: + +```python +import css_inline + +HTML = """<html> +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html>""" + +inlined = css_inline.inline(HTML) +# HTML becomes this: +# +# <html> +# <head> +# <title>Test</title> +# <style>h1 { color:blue; }</style> +# </head> +# <body> +# <h1 style="color:blue;">Big Text</h1> +# </body> +# </html> +``` + +If you want to inline many HTML documents, you can utilize `inline_many` that processes the input in parallel. + +```python +import css_inline + +css_inline.inline_many(["<...>", "<...>"]) +``` + +`inline_many` will spawn threads on the Rust level; thus, you can expect it's running faster than `css_inline.inline` via Python's `multiprocessing` or `threading` modules. + +For customization options use the `CSSInliner` class: + +```python +import css_inline + +inliner = css_inline.CSSInliner(remove_style_tags=True) +inliner.inline("...") +``` + +If you'd like to skip CSS inlining for an HTML tag, add `data-css-inline="ignore"` attribute to it: + +```html +<head> + <title>Test</title> + <style>h1 { color:blue; }</style> +</head> +<body> + <!-- The tag below won't receive additional styles --> + <h1 data-css-inline="ignore">Big Text</h1> +</body> +</html> +``` + +This attribute also allows you to skip `link` and `style` tags: + +```html +<head> + <title>Test</title> + <!-- Styles below are ignored --> + <style data-css-inline="ignore">h1 { color:blue; }</style> +</head> +<body> + <h1>Big Text</h1> +</body> +</html> +``` + +If you'd like to load stylesheets from your filesystem, use the `file://` scheme: + +```python +import css_inline + +# styles/email is relative to the current directory +inliner = css_inline.CSSInliner(base_url="file://styles/email/") +inliner.inline("...") +``` + +## Standards support & restrictions + +`css-inline` is built on top of [kuchiki](https://crates.io/crates/kuchiki) and [cssparser](https://crates.io/crates/cssparser) and relies on their behavior for HTML / CSS parsing and serialization. +Notably: + +- Only HTML 5, XHTML is not supported; +- Only CSS 3; +- Only UTF-8 for string representation. Other document encodings are not yet supported. + +If you'd like to work around some XHTML compatibility issues like closing empty tags (`<hr>` vs. `<hr/>`), you can use the following snippet that involves `lxml`: + +```python +import css_inline +from lxml import html, etree + +document = "..." # Your HTML document +inlined = css_inline.inline(document) +tree = html.fromstring(inlined) +inlined = etree.tostring(tree).decode(encoding="utf-8") +``` + +## Performance + +Due to the usage of efficient tooling from Mozilla's Servo project (`html5ever`, `rust-cssparser` and others) this +library has excellent performance characteristics. In comparison with other Python projects, it is usually >10x faster than the nearest alternative. + +For inlining CSS in the html document from the `Usage` section above there is the following breakdown in the benchmarks: + +- `css_inline 0.8.2` - 22.42 us +- `premailer 3.10.0` - 332.02 us (**x14.81**) +- `toronado 0.1.0` - 1.59 ms (**x71.17**) +- `inlinestyler 0.2.5` - 2.35 ms (**x105.07**) +- `pynliner 0.8.0` - 2.79 ms (**x124.80**) + +Realistic email 1: + +- `css_inline 0.8.2` - 487.75 us +- `premailer 3.10.0` - 3.92 ms (**x8.05**) +- `toronado 0.1.0` - 52.09 ms (**x106.81**) +- `inlinestyler 0.2.5` - 81.17 ms (**x166.43**) +- `pynliner 0.8.0` - 128.81 ms (**x264.1**) + +Realistic email 2: + +- `css_inline 0.8.2` - 386.64 us +- `premailer 3.10.0` - 4.82 ms (**x12.47**) +- `toronado 0.1.0` - `Error: Pseudo-elements are not supported` +- `inlinestyler 0.2.5` - 40.80 ms (**x105.54**) +- `pynliner 0.8.0` - `Error: No match was found` + +You can take a look at the benchmarks' code at `benches/bench.py` file. +The results above were measured with stable `rustc 1.64.0`, `Python 3.10.4`, `Linux x86_64` on i8700K, and 32GB RAM. + +## Comparison with other libraries + +Besides performance, `css-inline` differs from other Python libraries for CSS inlining. + +- Generally supports more CSS features than other libraries (for example, `toronado` and `pynliner` do not support pseudo-elements); +- It has fewer configuration options and not as flexible as `premailer`; +- Works on fewer platforms than LXML-based libraries (`premailer`, `inlinestyler`, `toronado`, and optionally `pynliner`); +- Does not have debug logs yet; +- Supports only HTML 5. + +## Python support + +`css_inline` supports CPython 3.7, 3.8, 3.9, 3.10, 3.11 and PyPy 3.7, 3.8, 3.9. + +## Extra materials + +If you want to know how this library was created & how it works internally, you could take a look at these articles: + +- [Rust crate](https://dygalo.dev/blog/rust-for-a-pythonista-2/) +- [Python bindings](https://dygalo.dev/blog/rust-for-a-pythonista-3/) + +## License + +The code in this project is licensed under [MIT license](https://opensource.org/licenses/MIT). +By contributing to `css_inline`, you agree that your contributions +will be licensed under its MIT license. + + + +%prep +%autosetup -n css-inline-0.8.7 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-css-inline -f filelist.lst +%dir %{python3_sitearch}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Tue Apr 11 2023 Python_Bot <Python_Bot@openeuler.org> - 0.8.7-1 +- Package Spec generated @@ -0,0 +1 @@ +03fb6e256d4382bdc308982cc5ebb29b css_inline-0.8.7.tar.gz |