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:
- 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
'%(...))
- All colors are auto-formatted to
#nnnnnn(for example,#f7e923) - Does not preserve CSS comments
- JavaScript evaluation
- Python 3.11+
pip
Install from PyPI:
pip install lesscpyCreate 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 source and wheel distributions:
python -m pip install --upgrade build
python -m buildArtifacts are created in dist/.
Run unit tests:
pytest -vRun lint checks:
flake8tox 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]"
toxRun a single environment:
tox -e py3.12
tox -e flake8usage: lesscpy [-h] [-v] [-I INCLUDE] [-V] [-C] [-x] [-X] [-t] [-s SPACES]
[-o OUT] [-r] [-f] [-m] [-D] [-g] [-S] [-L] [-N]
target [output]
from io import StringIO
import lesscpy
print(lesscpy.compile(StringIO("a { border-width: 2px * 3; }"), minify=True))Output:
a{border-width:6px;}
See the LICENSE file.
