Skip to content

Commit

Permalink
Merge pull request lesscpy#107 from saschpe/cleanups
Browse files Browse the repository at this point in the history
Cleanups
  • Loading branch information
saschpe authored Jan 23, 2020
2 parents 6caabcd + 9c96760 commit b5a83ea
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
install:
# setup.py test (script) fetches all test_require files, thus no pip needed
#- pip install --use-mirrors -r test-requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Not supported
Requirements
------------

- Python 2.7, 3.4, 3.5 or 3.6
- Python 2.7, 3.4, 3.5, 3.6 or 3.7
- ply (Python Lex-Yacc) (check requirements.txt)
- six

Expand Down
6 changes: 3 additions & 3 deletions lesscpy/lessc/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from lesscpy.lib import colors


class Color():
class Color:
def process(self, expression):
""" Process color expression
args:
Expand Down Expand Up @@ -133,8 +133,8 @@ def argb(self, *args):
rgb = [255] + rgb[1:] # Clip invalid integer/float values
elif 1 >= fval >= 0:
rgb = [
fval * 256
] + rgb[1:] # Convert 0-1 to 0-255 range for _rgbatohex
fval * 256
] + rgb[1:] # Convert 0-1 to 0-255 range for _rgbatohex
else:
rgb = [0] + rgb[1:] # Clip lower bound
return self._rgbatohex(list(map(int, rgb)))
Expand Down
22 changes: 4 additions & 18 deletions lesscpy/lessc/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,9 @@ class LessLexer:
]
tokens += list(set(reserved.tokens.values()))
# Tokens with significant following whitespace
significant_ws = set([
'css_class',
'css_id',
'css_dom',
'css_property',
'css_vendor_property',
'css_ident',
'css_number',
'css_color',
'css_media_type',
'css_filter',
'less_variable',
't_and',
't_not',
't_only',
'&',
])
significant_ws = {'css_class', 'css_id', 'css_dom', 'css_property', 'css_vendor_property', 'css_ident',
'css_number', 'css_color', 'css_media_type', 'css_filter', 'less_variable', 't_and', 't_not',
't_only', '&'}
significant_ws.update(reserved.tokens.values())

def __init__(self):
Expand Down Expand Up @@ -138,7 +124,7 @@ def t_css_ident(self, t):
t.type = 'less_not'
elif v in ('from', 'to'):
t.type = 'css_keyframe_selector'
elif v in css.propertys:
elif v in css.properties:
t.type = 'css_property'
t.lexer.in_property_decl = True
elif (v in dom.elements
Expand Down
2 changes: 1 addition & 1 deletion lesscpy/lessc/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def mixins(self, name):
def _smixins(self, name):
"""Inner wrapper to search for mixins by name.
"""
return (self._mixins[name] if name in self._mixins else False)
return self._mixins[name] if name in self._mixins else False

def blocks(self, name):
"""
Expand Down
13 changes: 7 additions & 6 deletions lesscpy/lessc/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
except ImportError:
from collections import Iterable


def flatten(lst):
"""Flatten list.
Args:
Expand Down Expand Up @@ -138,16 +139,16 @@ def analyze_number(var, err=''):
"""
n, u = split_unit(var)
if not isinstance(var, string_types):
return (var, u)
return var, u
if is_color(var):
return (var, 'color')
return var, 'color'
if is_int(n):
n = int(n)
elif is_float(n):
n = float(n)
else:
raise SyntaxError('%s ´%s´' % (err, var))
return (n, u)
return n, u


def with_unit(number, unit=None):
Expand Down Expand Up @@ -196,10 +197,10 @@ def is_variable(value):
bool
"""
if isinstance(value, string_types):
return (value.startswith('@') or value.startswith('-@'))
return value.startswith('@') or value.startswith('-@')
elif isinstance(value, tuple):
value = ''.join(value)
return (value.startswith('@') or value.startswith('-@'))
return value.startswith('@') or value.startswith('-@')
return False


Expand Down Expand Up @@ -252,7 +253,7 @@ def away_from_zero_round(value, ndigits=0):
Python2's round() method.
"""
if sys.version_info[0] >= 3:
p = 10**ndigits
p = 10 ** ndigits
return float(math.floor((value * p) + math.copysign(0.5, value))) / p
else:
return round(value, ndigits)
Expand Down
2 changes: 1 addition & 1 deletion lesscpy/lib/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
'behavior',
'zoom',
]
propertys = css2 + css3 + svg + vendor_ugly
properties = css2 + css3 + svg + vendor_ugly

# CSS-2(.1) media types: http://www.w3.org/TR/CSS2/media.html#media-types
# Include media types as defined in HTML4: http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13
Expand Down
2 changes: 1 addition & 1 deletion lesscpy/plib/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def parse(self, scope):
for p in inner:
if p is not None:
if isinstance(p, Block):
if (len(scope) == 2 and p.tokens[1] is not None):
if len(scope) == 2 and p.tokens[1] is not None:
p_is_mediaquery = p.name.tokens[0] == '@media'
# Inner block @media ... { ... } is a nested media
# query. But double-nested media queries have to be
Expand Down
6 changes: 3 additions & 3 deletions lesscpy/plib/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def iscolor(self, string, *args):
returns:
bool
"""
return (string in lessColors)
return string in lessColors

def isurl(self, string, *args):
"""Is url
Expand Down Expand Up @@ -159,7 +159,7 @@ def iskeyword(self, string, *args):
returns:
bool
"""
return (string in ('when', 'and', 'not'))
return string in ('when', 'and', 'not')

def increment(self, value, *args):
""" Increment function
Expand Down Expand Up @@ -188,7 +188,7 @@ def add(self, *args):
returns:
str
"""
if (len(args) <= 1):
if len(args) <= 1:
return 0
return sum([int(v) for v in args])

Expand Down
4 changes: 3 additions & 1 deletion scripts/lesscpy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Lesscpy run script
<[email protected]>
"""
import sys, os
import os
import sys

path = os.path.abspath(sys.argv[0])
while os.path.dirname(path) != path:
Expand All @@ -13,4 +14,5 @@ while os.path.dirname(path) != path:
path = os.path.dirname(path)

from lesscpy.scripts import compiler

compiler.run()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Code Generators',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py34,py35,p36,pypy,pypy3
envlist = py27,py35,py36,py37,py38,pypy,pypy3
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit b5a83ea

Please sign in to comment.