lightningcss 0.2.2__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lightningcss-0.2.2 → lightningcss-0.3.1}/Cargo.lock +11 -13
- {lightningcss-0.2.2 → lightningcss-0.3.1}/Cargo.toml +3 -2
- {lightningcss-0.2.2 → lightningcss-0.3.1}/PKG-INFO +45 -10
- lightningcss-0.3.1/README.md +70 -0
- {lightningcss-0.2.2 → lightningcss-0.3.1}/pyproject.toml +3 -0
- {lightningcss-0.2.2 → lightningcss-0.3.1}/src/lib.rs +65 -1
- lightningcss-0.2.2/README.md +0 -37
- {lightningcss-0.2.2 → lightningcss-0.3.1}/.github/workflows/CI.yml +0 -0
- {lightningcss-0.2.2 → lightningcss-0.3.1}/.gitignore +0 -0
- {lightningcss-0.2.2 → lightningcss-0.3.1}/LICENSE +0 -0
- {lightningcss-0.2.2 → lightningcss-0.3.1}/lightningcss.pyi +0 -0
|
@@ -694,11 +694,10 @@ dependencies = [
|
|
|
694
694
|
|
|
695
695
|
[[package]]
|
|
696
696
|
name = "pyo3"
|
|
697
|
-
version = "0.
|
|
697
|
+
version = "0.27.2"
|
|
698
698
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
699
|
-
checksum = "
|
|
699
|
+
checksum = "ab53c047fcd1a1d2a8820fe84f05d6be69e9526be40cb03b73f86b6b03e6d87d"
|
|
700
700
|
dependencies = [
|
|
701
|
-
"cfg-if",
|
|
702
701
|
"indoc",
|
|
703
702
|
"libc",
|
|
704
703
|
"memoffset",
|
|
@@ -712,19 +711,18 @@ dependencies = [
|
|
|
712
711
|
|
|
713
712
|
[[package]]
|
|
714
713
|
name = "pyo3-build-config"
|
|
715
|
-
version = "0.
|
|
714
|
+
version = "0.27.2"
|
|
716
715
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
717
|
-
checksum = "
|
|
716
|
+
checksum = "b455933107de8642b4487ed26d912c2d899dec6114884214a0b3bb3be9261ea6"
|
|
718
717
|
dependencies = [
|
|
719
|
-
"once_cell",
|
|
720
718
|
"target-lexicon",
|
|
721
719
|
]
|
|
722
720
|
|
|
723
721
|
[[package]]
|
|
724
722
|
name = "pyo3-ffi"
|
|
725
|
-
version = "0.
|
|
723
|
+
version = "0.27.2"
|
|
726
724
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
727
|
-
checksum = "
|
|
725
|
+
checksum = "1c85c9cbfaddf651b1221594209aed57e9e5cff63c4d11d1feead529b872a089"
|
|
728
726
|
dependencies = [
|
|
729
727
|
"libc",
|
|
730
728
|
"pyo3-build-config",
|
|
@@ -732,9 +730,9 @@ dependencies = [
|
|
|
732
730
|
|
|
733
731
|
[[package]]
|
|
734
732
|
name = "pyo3-macros"
|
|
735
|
-
version = "0.
|
|
733
|
+
version = "0.27.2"
|
|
736
734
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
737
|
-
checksum = "
|
|
735
|
+
checksum = "0a5b10c9bf9888125d917fb4d2ca2d25c8df94c7ab5a52e13313a07e050a3b02"
|
|
738
736
|
dependencies = [
|
|
739
737
|
"proc-macro2",
|
|
740
738
|
"pyo3-macros-backend",
|
|
@@ -744,9 +742,9 @@ dependencies = [
|
|
|
744
742
|
|
|
745
743
|
[[package]]
|
|
746
744
|
name = "pyo3-macros-backend"
|
|
747
|
-
version = "0.
|
|
745
|
+
version = "0.27.2"
|
|
748
746
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
749
|
-
checksum = "
|
|
747
|
+
checksum = "03b51720d314836e53327f5871d4c0cfb4fb37cc2c4a11cc71907a86342c40f9"
|
|
750
748
|
dependencies = [
|
|
751
749
|
"heck",
|
|
752
750
|
"proc-macro2",
|
|
@@ -757,7 +755,7 @@ dependencies = [
|
|
|
757
755
|
|
|
758
756
|
[[package]]
|
|
759
757
|
name = "python-lightningcss"
|
|
760
|
-
version = "0.
|
|
758
|
+
version = "0.3.1"
|
|
761
759
|
dependencies = [
|
|
762
760
|
"browserslist-rs",
|
|
763
761
|
"lightningcss",
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "python-lightningcss"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.1"
|
|
4
4
|
edition = "2021"
|
|
5
|
+
readme = "README.md"
|
|
5
6
|
|
|
6
7
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
7
8
|
[lib]
|
|
@@ -9,6 +10,6 @@ name = "lightningcss"
|
|
|
9
10
|
crate-type = ["cdylib"]
|
|
10
11
|
|
|
11
12
|
[dependencies]
|
|
12
|
-
pyo3 = { version = "0.
|
|
13
|
+
pyo3 = { version = "0.27.2", features = ["extension-module"] }
|
|
13
14
|
browserslist-rs = "0.17.0"
|
|
14
15
|
lightningcss = { version = "1.0.0-alpha.65", features = ["browserslist"] }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lightningcss
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -15,6 +15,8 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
20
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
21
|
Classifier: Topic :: Software Development :: Pre-processors
|
|
20
22
|
License-File: LICENSE
|
|
@@ -41,11 +43,15 @@ or webpack](https://lightningcss.dev/docs.html) instead.
|
|
|
41
43
|
## Installation
|
|
42
44
|
|
|
43
45
|
python-lightningcss includes wheels which can be installed for most platforms
|
|
44
|
-
using pip:
|
|
46
|
+
using pip:
|
|
47
|
+
|
|
48
|
+
$ pip install lightningcss
|
|
45
49
|
|
|
46
50
|
Alternatively, python-lightningcss may be installed directly from source:
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
|
|
52
|
+
$ pip install git+https://github.com/pydsigner/python-lightningcss
|
|
53
|
+
|
|
54
|
+
This will require that the Rust toolchain be installed.
|
|
49
55
|
|
|
50
56
|
## Usage
|
|
51
57
|
|
|
@@ -53,14 +59,43 @@ require that the Rust toolchain be installed.
|
|
|
53
59
|
import lightningcss
|
|
54
60
|
|
|
55
61
|
parser_flags = lightningcss.calc_parser_flags(nesting=True)
|
|
62
|
+
|
|
56
63
|
input_css = """
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
.navbar {
|
|
65
|
+
margin: 0;
|
|
66
|
+
|
|
67
|
+
a {
|
|
68
|
+
padding-left: 0;
|
|
69
|
+
padding-right: 0;
|
|
70
|
+
padding-top: 5px;
|
|
71
|
+
padding-bottom: 5px;
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
"""
|
|
64
|
-
|
|
75
|
+
|
|
76
|
+
output_css = lightningcss.process_stylesheet(
|
|
77
|
+
input_css,
|
|
78
|
+
filename="abc.css",
|
|
79
|
+
parser_flags = parser_flags,
|
|
80
|
+
browsers_list = ['defaults'],
|
|
81
|
+
minify = True,
|
|
82
|
+
)
|
|
65
83
|
```
|
|
66
84
|
|
|
85
|
+
This package also supports creating a CSS bundle where all `@import` rules are
|
|
86
|
+
resolved into a single stylesheet:
|
|
87
|
+
|
|
88
|
+
```py
|
|
89
|
+
bundled_css = lightningcss.bundle_css(
|
|
90
|
+
"main.css",
|
|
91
|
+
filename = "main.css",
|
|
92
|
+
browsers_list = ["defaults"],
|
|
93
|
+
minify = False,
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
All resources referenced via `@import` are resolved relative to the main file. The
|
|
98
|
+
`filename` keyword parameter is only used for displaying error messages from the
|
|
99
|
+
parser. When using `browsers_list`, lightningcss will try to transpile the code
|
|
100
|
+
to be compatible with the specified [browserslist target](https://browsersl.ist/).
|
|
101
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://pypi.org/project/lightningcss)
|
|
2
|
+
[](https://pypi.org/project/lightningcss)
|
|
3
|
+
[](https://github.com/pydsigner/python-lightningcss)
|
|
4
|
+
|
|
5
|
+
# python-lightningcss
|
|
6
|
+
|
|
7
|
+
python-lightningcss offers PyO3 bindings to the lightningcss library. Presently
|
|
8
|
+
only a subset of functionality is exposed, intended for integration into a
|
|
9
|
+
Python-centric web application rather than a JavaScript-based workflow. If the
|
|
10
|
+
latter is needed, consider using the [official npm lightningcss module, parcel,
|
|
11
|
+
or webpack](https://lightningcss.dev/docs.html) instead.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
python-lightningcss includes wheels which can be installed for most platforms
|
|
16
|
+
using pip:
|
|
17
|
+
|
|
18
|
+
$ pip install lightningcss
|
|
19
|
+
|
|
20
|
+
Alternatively, python-lightningcss may be installed directly from source:
|
|
21
|
+
|
|
22
|
+
$ pip install git+https://github.com/pydsigner/python-lightningcss
|
|
23
|
+
|
|
24
|
+
This will require that the Rust toolchain be installed.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```py
|
|
29
|
+
import lightningcss
|
|
30
|
+
|
|
31
|
+
parser_flags = lightningcss.calc_parser_flags(nesting=True)
|
|
32
|
+
|
|
33
|
+
input_css = """
|
|
34
|
+
.navbar {
|
|
35
|
+
margin: 0;
|
|
36
|
+
|
|
37
|
+
a {
|
|
38
|
+
padding-left: 0;
|
|
39
|
+
padding-right: 0;
|
|
40
|
+
padding-top: 5px;
|
|
41
|
+
padding-bottom: 5px;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
output_css = lightningcss.process_stylesheet(
|
|
47
|
+
input_css,
|
|
48
|
+
filename="abc.css",
|
|
49
|
+
parser_flags = parser_flags,
|
|
50
|
+
browsers_list = ['defaults'],
|
|
51
|
+
minify = True,
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This package also supports creating a CSS bundle where all `@import` rules are
|
|
56
|
+
resolved into a single stylesheet:
|
|
57
|
+
|
|
58
|
+
```py
|
|
59
|
+
bundled_css = lightningcss.bundle_css(
|
|
60
|
+
"main.css",
|
|
61
|
+
filename = "main.css",
|
|
62
|
+
browsers_list = ["defaults"],
|
|
63
|
+
minify = False,
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
All resources referenced via `@import` are resolved relative to the main file. The
|
|
68
|
+
`filename` keyword parameter is only used for displaying error messages from the
|
|
69
|
+
parser. When using `browsers_list`, lightningcss will try to transpile the code
|
|
70
|
+
to be compatible with the specified [browserslist target](https://browsersl.ist/).
|
|
@@ -4,6 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "lightningcss"
|
|
7
|
+
dynamic = ["version"]
|
|
7
8
|
description = "Python bindings for lightningcss."
|
|
8
9
|
readme = "README.md"
|
|
9
10
|
requires-python = ">=3.7"
|
|
@@ -27,6 +28,8 @@ classifiers = [
|
|
|
27
28
|
"Programming Language :: Python :: 3.10",
|
|
28
29
|
"Programming Language :: Python :: 3.11",
|
|
29
30
|
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
30
33
|
"Topic :: Internet :: WWW/HTTP",
|
|
31
34
|
"Topic :: Software Development :: Pre-processors",
|
|
32
35
|
]
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
use std::collections::HashSet;
|
|
2
|
+
use std::path::Path;
|
|
2
3
|
|
|
3
4
|
use pyo3::exceptions::PyValueError;
|
|
4
5
|
use pyo3::prelude::*;
|
|
5
6
|
|
|
6
7
|
use browserslist::Error as BrowserslistError;
|
|
7
|
-
use lightningcss::
|
|
8
|
+
use lightningcss::bundler::{Bundler, FileProvider};
|
|
9
|
+
use lightningcss::stylesheet::{
|
|
10
|
+
MinifyOptions, ParserFlags, ParserOptions, PrinterOptions, StyleSheet,
|
|
11
|
+
};
|
|
8
12
|
use lightningcss::targets::{Browsers, Targets};
|
|
9
13
|
|
|
10
14
|
/// Processes provided CSS and returns as a string.
|
|
@@ -109,11 +113,71 @@ fn mk_printer_options<'a>(targets: &Targets,
|
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
115
|
|
|
116
|
+
/// Bundles a CSS file and returns as a string.
|
|
117
|
+
#[pyfunction]
|
|
118
|
+
#[pyo3(signature = (
|
|
119
|
+
path="",
|
|
120
|
+
/,
|
|
121
|
+
error_recovery=false,
|
|
122
|
+
parser_flags=0,
|
|
123
|
+
unused_symbols=None,
|
|
124
|
+
browsers_list=None,
|
|
125
|
+
minify=true,
|
|
126
|
+
))]
|
|
127
|
+
fn bundle_css(
|
|
128
|
+
path: &str,
|
|
129
|
+
error_recovery: bool,
|
|
130
|
+
parser_flags: u8,
|
|
131
|
+
unused_symbols: Option<HashSet<String>>,
|
|
132
|
+
browsers_list: Option<Vec<String>>,
|
|
133
|
+
minify: bool,
|
|
134
|
+
) -> PyResult<String> {
|
|
135
|
+
let fs = FileProvider::new();
|
|
136
|
+
let mut bundler = Bundler::new(
|
|
137
|
+
&fs,
|
|
138
|
+
None,
|
|
139
|
+
ParserOptions {
|
|
140
|
+
error_recovery: error_recovery,
|
|
141
|
+
flags: ParserFlags::from_bits_truncate(parser_flags),
|
|
142
|
+
..Default::default()
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
let mut stylesheet = bundler.bundle(Path::new(path)).unwrap();
|
|
146
|
+
|
|
147
|
+
let targets = match mk_targets(browsers_list) {
|
|
148
|
+
Ok(val) => val,
|
|
149
|
+
Err(e) => {
|
|
150
|
+
return Err(PyValueError::new_err(format!(
|
|
151
|
+
"browsers_list failed validation: {}",
|
|
152
|
+
e.to_string()
|
|
153
|
+
)))
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
match stylesheet.minify(mk_minify_options(unused_symbols, &targets)) {
|
|
158
|
+
Ok(_) => {}
|
|
159
|
+
Err(e) => {
|
|
160
|
+
return Err(PyValueError::new_err(format!(
|
|
161
|
+
"Minifying stylesheet failed: {}",
|
|
162
|
+
e.to_string()
|
|
163
|
+
)));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return match stylesheet.to_css(mk_printer_options(&targets, minify)) {
|
|
167
|
+
Ok(val) => Ok(val.code),
|
|
168
|
+
Err(e) => Err(PyValueError::new_err(format!(
|
|
169
|
+
"Printing stylesheet failed: {}",
|
|
170
|
+
e.to_string()
|
|
171
|
+
))),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
112
175
|
/// A python wrapper for core functionality of lightningcss.
|
|
113
176
|
#[pymodule]
|
|
114
177
|
#[pyo3(name = "lightningcss")]
|
|
115
178
|
fn pylightningcss(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
116
179
|
m.add_function(wrap_pyfunction!(process_stylesheet, m)?)?;
|
|
117
180
|
m.add_function(wrap_pyfunction!(calc_parser_flags, m)?)?;
|
|
181
|
+
m.add_function(wrap_pyfunction!(bundle_css, m)?)?;
|
|
118
182
|
Ok(())
|
|
119
183
|
}
|
lightningcss-0.2.2/README.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
[](https://pypi.org/project/lightningcss)
|
|
2
|
-
[](https://pypi.org/project/lightningcss)
|
|
3
|
-
[](https://github.com/pydsigner/python-lightningcss)
|
|
4
|
-
|
|
5
|
-
# python-lightningcss
|
|
6
|
-
|
|
7
|
-
python-lightningcss offers PyO3 bindings to the lightningcss library. Presently
|
|
8
|
-
only a subset of functionality is exposed, intended for integration into a
|
|
9
|
-
Python-centric web application rather than a JavaScript-based workflow. If the
|
|
10
|
-
latter is needed, consider using the [official npm lightningcss module, parcel,
|
|
11
|
-
or webpack](https://lightningcss.dev/docs.html) instead.
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
python-lightningcss includes wheels which can be installed for most platforms
|
|
16
|
-
using pip: `pip install lightningcss`.
|
|
17
|
-
|
|
18
|
-
Alternatively, python-lightningcss may be installed directly from source:
|
|
19
|
-
`pip install git+https://github.com/pydsigner/python-lightningcss`. This will
|
|
20
|
-
require that the Rust toolchain be installed.
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
```py
|
|
25
|
-
import lightningcss
|
|
26
|
-
|
|
27
|
-
parser_flags = lightningcss.calc_parser_flags(nesting=True)
|
|
28
|
-
input_css = """
|
|
29
|
-
a {
|
|
30
|
-
padding-left: 0;
|
|
31
|
-
padding-right: 0;
|
|
32
|
-
padding-top: 5px;
|
|
33
|
-
padding-bottom: 5px;
|
|
34
|
-
}
|
|
35
|
-
"""
|
|
36
|
-
output_css = lightningcss.process_stylesheet(input_css, filename="abc.css", browsers_list=['defaults'])
|
|
37
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|