LESSCPY
Python LESS Compiler.
A compiler written in Python for the LESS language. For those of us not willing or able to have node.js installed in our environment. Not all features of LESS are supported. Some features will probably never be supported (JavaScript evaluation). This program uses PLY (Python Lex-Yacc) to tokenize / parse the input and is considerably slower than the Node.js compiler.
For more information on LESS:
Development files:
Supported features
- Variables
- String interpolation
- Mixins (nested, calls, closures, recursive)
- Guard expressions
- Parametered mixins (class / id)
@arguments- Nesting
- Escapes
~/e() - Expressions
- Keyframe blocks
- Color functions (lighten, darken, saturate, desaturate, spin, hue, mix, saturation, lightness)
- Other functions (round, increment, decrement, format
'%(...))
Differences from less.js
- All colors are auto-formatted to
#nnnnnn(for example,#f7e923) - Does not preserve CSS comments
Not supported
- JavaScript evaluation
Requirements
- Python 3.11+
pip
Installation
Install from PyPI:
pip install lesscpy
Local setup
Create and activate a virtual environment, then install test dependencies from pyproject.toml:
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[test]"
Build
Build source and wheel distributions:
python -m pip install --upgrade build
python -m build
Artifacts are created in dist/.
Test
Run unit tests:
pytest -v
Run lint checks:
flake8
Using tox
tox is useful for running the project test workflow in isolated environments and for reproducing the same multi-version checks used in CI.
Run all configured environments:
python -m pip install -e ".[tox]"
tox
Run a single environment:
tox -e py3.12
tox -e flake8
Compiler script usage
usage: lesscpy [-h] [-v] [-I INCLUDE] [-V] [-C] [-x] [-X] [-t] [-s SPACES]
[-o OUT] [-r] [-f] [-m] [-D] [-g] [-S] [-L] [-N]
target [output]
Python usage
from io import StringIO
import lesscpy
print(lesscpy.compile(StringIO("a { border-width: 2px * 3; }"), minify=True))
Output:
a{border-width:6px;}
License
See the LICENSE file.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lesscpy-0.15.2.tar.gz.
File metadata
- Download URL: lesscpy-0.15.2.tar.gz
- Upload date:
- Size: 153.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f6b7f34c22c5ce137e7ee280dcb1984ade0d500b6dab591d4a4d84252d18de9
|
|
| MD5 |
e2c1f1f31caf92e645d77a6534d4f30a
|
|
| BLAKE2b-256 |
8e7adaf1c09148be007f6afc3d224afb548c64910772619a083a0a331556d78a
|
Provenance
The following attestation bundles were made for lesscpy-0.15.2.tar.gz:
Publisher:
main.yml on lesscpy/lesscpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lesscpy-0.15.2.tar.gz -
Subject digest:
4f6b7f34c22c5ce137e7ee280dcb1984ade0d500b6dab591d4a4d84252d18de9 - Sigstore transparency entry: 2289820554
- Sigstore integration time:
-
Permalink:
lesscpy/lesscpy@f5ed2b0ff526fd401ac81ad06449616bbf9eb368 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lesscpy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f5ed2b0ff526fd401ac81ad06449616bbf9eb368 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lesscpy-0.15.2-py3-none-any.whl.
File metadata
- Download URL: lesscpy-0.15.2-py3-none-any.whl
- Upload date:
- Size: 45.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39da3e9779674889fc67b50d16dff267677e7594cdc9da897e486f6244fd2b1b
|
|
| MD5 |
214baae7e12c0aee06a43a869efe7745
|
|
| BLAKE2b-256 |
759eac02bb38b217d657afe2edb8c9048d6f4008526d1b19e0e69f9fa5336aaa
|
Provenance
The following attestation bundles were made for lesscpy-0.15.2-py3-none-any.whl:
Publisher:
main.yml on lesscpy/lesscpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lesscpy-0.15.2-py3-none-any.whl -
Subject digest:
39da3e9779674889fc67b50d16dff267677e7594cdc9da897e486f6244fd2b1b - Sigstore transparency entry: 2289820570
- Sigstore integration time:
-
Permalink:
lesscpy/lesscpy@f5ed2b0ff526fd401ac81ad06449616bbf9eb368 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lesscpy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@f5ed2b0ff526fd401ac81ad06449616bbf9eb368 -
Trigger Event:
push
-
Statement type: