Skip to main content

Python LESS compiler

Project description

https://travis-ci.org/lesscpy/lesscpy.png?branch=master https://coveralls.io/repos/lesscpy/lesscpy/badge.png https://img.shields.io/pypi/dm/lesscpy.svg https://img.shields.io/pypi/v/lesscpy.svg Wheel Status License

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 (yet). Some features wil probably never be supported (JavaScript evaluation). This program uses PLY (Python Lex-Yacc) to tokenize / parse the input and is considerably slower than the NodeJS compiler. The plan is to utilize this to build in proper syntax checking and perhaps YUI compressing.

This is an early version, so you are likely to find bugs.

For more information on LESS:

http://lesscss.org/ or https://github.com/cloudhead/less.js

Development files:

https://github.com/lesscpy/lesscpy

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. eg, #f7e923

  • Does not preserve CSS comments

Not supported

  • JavaScript evaluation

Requirements

  • Python 3.4 - 3.9,

  • ply (Python Lex-Yacc) (check requirements.txt)

  • six

Installation

To install lesscpy from the Python Package Index, simply:

$ pip install lesscpy

To do a local system-wide install:

python setup.py install

Or simply place the package into your Python path. Or rather use packages provided by your distribution (openSUSE has them at least).

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]

LessCss Compiler

positional arguments:
  target                less file or directory
  output                output file path

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -I INCLUDE, --include INCLUDE
                        Included less-files (comma separated)
  -V, --verbose         Verbose mode
  -C, --dont_create_dirs
                        Creates directories when outputing files (lessc non-
                        compatible)

Formatting options:
  -x, --minify          Minify output
  -X, --xminify         Minify output, no end of block newlines
  -t, --tabs            Use tabs
  -s SPACES, --spaces SPACES
                        Number of startline spaces (default 2)

Directory options:
  Compiles all *.less files in directory that have a newer timestamp than
  it's css file.

  -o OUT, --out OUT     Output directory
  -r, --recurse         Recursive into subdirectorys
  -f, --force           Force recompile on all files
  -m, --min-ending      Add '.min' into output filename. eg, name.min.css
  -D, --dry-run         Dry run, do not write files

Debugging:
  -g, --debug           Debugging information
  -S, --scopemap        Scopemap
  -L, --lex-only        Run lexer on target
  -N, --no-css          No css output

<< jtm@robot.is @_o >>

Python usage

If you want to use the compiler from within Python, you can do it like this:

import lesscpy
from six import StringIO

print(lesscpy.compile(StringIO(u"a { border-width: 2px * 3; }"), minify=True))

The output will be:

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

lesscpy-0.15.0.tar.gz (176.9 kB view details)

Uploaded Source

Built Distribution

lesscpy-0.15.0-py2.py3-none-any.whl (46.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lesscpy-0.15.0.tar.gz.

File metadata

  • Download URL: lesscpy-0.15.0.tar.gz
  • Upload date:
  • Size: 176.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for lesscpy-0.15.0.tar.gz
Algorithm Hash digest
SHA256 ef058fb3fca077f0136222c415bc6d20fe256e92648ccbf4b3de874ba03b9b9d
MD5 fe0d4624156d7fe201e903aad455859f
BLAKE2b-256 6274af0a9d0051857de9cae6e71468f697c3cb03141a12ea363583ac72bfa3c3

See more details on using hashes here.

File details

Details for the file lesscpy-0.15.0-py2.py3-none-any.whl.

File metadata

  • Download URL: lesscpy-0.15.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 46.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for lesscpy-0.15.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7f7437df153ca9221beb5425c189d1523f95f864d1400f311598527ff03248d7
MD5 a14663355237c824704c4808b445d994
BLAKE2b-256 11d27002d5c3ab52c817f24622df0f0cad739169ab7af77b20dfc9dcfa4252dc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page