Skip to content

Commit f1dd8ce

Browse files
committed
Improved linting with autoflake, black and isort.
1 parent 197839a commit f1dd8ce

19 files changed

+901
-736
lines changed

setup.py

Lines changed: 71 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,121 +7,117 @@
77

88
from setuptools import setup
99

10-
extra = {'ext_modules': []}
10+
extra = {"ext_modules": []}
1111
try:
1212
from Cython.Build import cythonize
13-
p = os.path.join('src', 'wheezy', 'html')
14-
extra['ext_modules'] += cythonize(
15-
[os.path.join(p, '*.py'),
16-
os.path.join(p, 'ext', '*.py')],
17-
exclude=[os.path.join(p, '__init__.py'),
18-
os.path.join(p, 'ext', '__init__.py')],
19-
nthreads=2, quiet=True)
13+
14+
p = os.path.join("src", "wheezy", "html")
15+
extra["ext_modules"] += cythonize(
16+
[os.path.join(p, "*.py"), os.path.join(p, "ext", "*.py")],
17+
exclude=[
18+
os.path.join(p, "__init__.py"),
19+
os.path.join(p, "ext", "__init__.py"),
20+
],
21+
nthreads=2,
22+
quiet=True,
23+
)
2024
except ImportError:
2125
pass
2226

23-
can_build_ext = getattr(
24-
platform, 'python_implementation',
25-
lambda: None
26-
)() != 'PyPy' and 'java' not in sys.platform
27+
can_build_ext = (
28+
getattr(platform, "python_implementation", lambda: None)() != "PyPy"
29+
and "java" not in sys.platform
30+
)
2731

2832
if can_build_ext: # noqa: C901
29-
from distutils.core import Extension # noqa
3033
from distutils.command.build_ext import build_ext # noqa
31-
sources = [os.path.join('src', 'wheezy', 'html', 'boost.c')]
32-
extra['ext_modules'] += [Extension('wheezy.html.boost', sources)]
34+
from distutils.core import Extension # noqa
3335

34-
class BuildExtOptional(build_ext):
36+
sources = [os.path.join("src", "wheezy", "html", "boost.c")]
37+
extra["ext_modules"] += [Extension("wheezy.html.boost", sources)]
3538

39+
class BuildExtOptional(build_ext):
3640
def run(self):
3741
from distutils.errors import DistutilsPlatformError
42+
3843
try:
3944
build_ext.run(self)
4045
except DistutilsPlatformError:
4146
self.warn()
4247

4348
def build_extension(self, ext):
44-
from distutils.errors import CCompilerError
45-
from distutils.errors import DistutilsExecError
49+
from distutils.errors import CCompilerError, DistutilsExecError
50+
4651
try:
4752
build_ext.build_extension(self, ext)
4853
except (CCompilerError, DistutilsExecError):
4954
self.warn()
5055

5156
def warn(self):
52-
print(' WARNING '.center(44, '*'))
53-
print('An optional extension could not be compiled.')
57+
print(" WARNING ".center(44, "*"))
58+
print("An optional extension could not be compiled.")
5459

55-
extra['cmdclass'] = {'build_ext': BuildExtOptional}
60+
extra["cmdclass"] = {"build_ext": BuildExtOptional}
5661

57-
README = open(os.path.join(os.path.dirname(__file__), 'README.md')).read()
62+
README = open(os.path.join(os.path.dirname(__file__), "README.md")).read()
5863
VERSION = (
5964
re.search(
60-
r'__version__ = "(.+)"',
61-
open("src/wheezy/html/__init__.py").read(),
65+
r'__version__ = "(.+)"', open("src/wheezy/html/__init__.py").read(),
6266
)
6367
.group(1)
6468
.strip()
6569
)
6670

6771
setup(
68-
name='wheezy.html',
72+
name="wheezy.html",
6973
version=VERSION,
70-
description='A lightweight html rendering library',
74+
description="A lightweight html rendering library",
7175
long_description=README,
72-
long_description_content_type='text/markdown',
73-
url='https://github.com/akornatskyy/wheezy.html',
74-
author='Andriy Kornatskyy',
75-
author_email='andriy.kornatskyy@live.com',
76-
license='MIT',
76+
long_description_content_type="text/markdown",
77+
url="https://github.com/akornatskyy/wheezy.html",
78+
author="Andriy Kornatskyy",
79+
author_email="andriy.kornatskyy@live.com",
80+
license="MIT",
7781
classifiers=[
78-
'Environment :: Web Environment',
79-
'Intended Audience :: Developers',
80-
'License :: OSI Approved :: MIT License',
81-
'Natural Language :: English',
82-
'Operating System :: OS Independent',
83-
'Programming Language :: Python',
84-
'Programming Language :: Python :: 2',
85-
'Programming Language :: Python :: 2.4',
86-
'Programming Language :: Python :: 2.5',
87-
'Programming Language :: Python :: 2.6',
88-
'Programming Language :: Python :: 2.7',
89-
'Programming Language :: Python :: 3',
90-
'Programming Language :: Python :: 3.2',
91-
'Programming Language :: Python :: 3.3',
92-
'Programming Language :: Python :: 3.4',
93-
'Programming Language :: Python :: 3.5',
94-
'Programming Language :: Python :: 3.6',
95-
'Programming Language :: Python :: 3.7',
96-
'Programming Language :: Python :: 3.8',
97-
'Programming Language :: Python :: Implementation :: CPython',
98-
'Programming Language :: Python :: Implementation :: PyPy',
99-
'Topic :: Internet :: WWW/HTTP',
100-
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
101-
'Topic :: Software Development :: Libraries :: Python Modules',
102-
'Topic :: Software Development :: Widget Sets',
103-
'Topic :: Text Processing :: Markup :: HTML'
82+
"Environment :: Web Environment",
83+
"Intended Audience :: Developers",
84+
"License :: OSI Approved :: MIT License",
85+
"Natural Language :: English",
86+
"Operating System :: OS Independent",
87+
"Programming Language :: Python",
88+
"Programming Language :: Python :: 2",
89+
"Programming Language :: Python :: 2.4",
90+
"Programming Language :: Python :: 2.5",
91+
"Programming Language :: Python :: 2.6",
92+
"Programming Language :: Python :: 2.7",
93+
"Programming Language :: Python :: 3",
94+
"Programming Language :: Python :: 3.2",
95+
"Programming Language :: Python :: 3.3",
96+
"Programming Language :: Python :: 3.4",
97+
"Programming Language :: Python :: 3.5",
98+
"Programming Language :: Python :: 3.6",
99+
"Programming Language :: Python :: 3.7",
100+
"Programming Language :: Python :: 3.8",
101+
"Programming Language :: Python :: Implementation :: CPython",
102+
"Programming Language :: Python :: Implementation :: PyPy",
103+
"Topic :: Internet :: WWW/HTTP",
104+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
105+
"Topic :: Software Development :: Libraries :: Python Modules",
106+
"Topic :: Software Development :: Widget Sets",
107+
"Topic :: Text Processing :: Markup :: HTML",
104108
],
105-
keywords='html widget markup mako jinja2 tenjin wheezy.template '
106-
'preprocessor',
107-
packages=['wheezy', 'wheezy.html', 'wheezy.html.ext'],
108-
package_dir={'': 'src'},
109-
namespace_packages=['wheezy'],
109+
keywords="html widget markup mako jinja2 tenjin wheezy.template "
110+
"preprocessor",
111+
packages=["wheezy", "wheezy.html", "wheezy.html.ext"],
112+
package_dir={"": "src"},
113+
namespace_packages=["wheezy"],
110114
zip_safe=False,
111115
extras_require={
112-
'mako': [
113-
'mako>=0.7.0'
114-
],
115-
'tenjin': [
116-
'tenjin>=1.1.0'
117-
],
118-
'jinja2': [
119-
'jinja2>=2.6'
120-
],
121-
'wheezy.template': [
122-
'wheezy.template>=0.1.88'
123-
]
116+
"mako": ["mako>=0.7.0"],
117+
"tenjin": ["tenjin>=1.1.0"],
118+
"jinja2": ["jinja2>=2.6"],
119+
"wheezy.template": ["wheezy.template>=0.1.88"],
124120
},
125-
platforms='any',
121+
platforms="any",
126122
**extra
127123
)

src/wheezy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# See
22
# http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
33
try:
4-
__import__('pkg_resources').declare_namespace(__name__)
4+
__import__("pkg_resources").declare_namespace(__name__)
55
except ImportError:
66
from pkgutil import extend_path
7+
78
__path__ = extend_path(__path__, __name__)

src/wheezy/html/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
"""
43

src/wheezy/html/comp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
21
""" ``comp`` module.
32
"""
43

54
import sys
65

7-
86
PY3 = sys.version_info[0] >= 3
97

108

@@ -20,6 +18,8 @@
2018

2119
def iteritems(d):
2220
return d.items()
21+
22+
2323
else: # pragma: nocover
2424

2525
def iteritems(d):

src/wheezy/html/ext/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
21
""" ``ext`` package.
32
"""

src/wheezy/html/ext/jinja2.py

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,54 @@
1-
21
""" ``jinja2`` extension module.
32
"""
43

54
import re
65

7-
from wheezy.html.ext.lexer import InlinePreprocessor
8-
from wheezy.html.ext.lexer import Preprocessor
9-
from wheezy.html.ext.lexer import WhitespacePreprocessor
10-
6+
from wheezy.html.ext.lexer import (
7+
InlinePreprocessor,
8+
Preprocessor,
9+
WhitespacePreprocessor,
10+
)
1111

1212
# from jinja2.ext import Extension
13-
Extension = __import__('jinja2.ext', None, None, ['Extension']).Extension
13+
Extension = __import__("jinja2.ext", None, None, ["Extension"]).Extension
1414

1515

1616
class Jinja2Preprocessor(Preprocessor):
17-
18-
def __init__(self,
19-
variable_start_string=None,
20-
variable_end_string=None):
21-
pattern = r'\{\{((?P<expr>.+?)\.'\
22-
r'(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*'\
23-
r'(?P<expr_filter>(\|\s*[\w,\s]+?|\s*)))\}\}'
17+
def __init__(self, variable_start_string=None, variable_end_string=None):
18+
pattern = (
19+
r"\{\{((?P<expr>.+?)\."
20+
r"(?P<widget>%(widgets)s){1}\((?P<params>.*?)\)\s*"
21+
r"(?P<expr_filter>(\|\s*[\w,\s]+?|\s*)))\}\}"
22+
)
2423
if variable_start_string:
25-
pattern = pattern.replace('\{\{', # noqa: W605
26-
re.escape(variable_start_string))
24+
pattern = pattern.replace(
25+
"\{\{", re.escape(variable_start_string) # noqa: W605
26+
)
2727
if variable_end_string:
28-
pattern = pattern.replace('\}\}', # noqa: W605
29-
re.escape(variable_end_string))
28+
pattern = pattern.replace(
29+
"\}\}", re.escape(variable_end_string) # noqa: W605
30+
)
3031
super(Jinja2Preprocessor, self).__init__(pattern)
3132

3233
attrs = [
33-
'EXPRESSION', 'ERROR', 'SELECT', 'INPUT', 'CHECKBOX',
34-
'MULTIPLE_CHECKBOX', 'MULTIPLE_HIDDEN', 'RADIO',
35-
'MULTIPLE_SELECT'
34+
"EXPRESSION",
35+
"ERROR",
36+
"SELECT",
37+
"INPUT",
38+
"CHECKBOX",
39+
"MULTIPLE_CHECKBOX",
40+
"MULTIPLE_HIDDEN",
41+
"RADIO",
42+
"MULTIPLE_SELECT",
3643
]
3744
c = self.__class__.__dict__
3845
for attr in attrs:
3946
t = c[attr]
40-
t = t.replace('{{', variable_start_string)
41-
t = t.replace('}}', variable_end_string)
47+
t = t.replace("{{", variable_start_string)
48+
t = t.replace("}}", variable_end_string)
4249
self.__dict__[attr] = t
4350

44-
EXPRESSION = '{{ %(expr)s%(expr_filter)s }}'
51+
EXPRESSION = "{{ %(expr)s%(expr_filter)s }}"
4552

4653
ERROR_CLASS0 = """\
4754
{%% if '%(name)s' in errors: %%}\
@@ -131,44 +138,52 @@ def __init__(self,
131138

132139

133140
class WidgetExtension(Extension):
134-
135141
def __init__(self, environment):
136142
super(WidgetExtension, self).__init__(environment)
137143
self.preprocessor = Jinja2Preprocessor(
138144
variable_start_string=environment.variable_start_string,
139-
variable_end_string=environment.variable_end_string)
145+
variable_end_string=environment.variable_end_string,
146+
)
140147

141148
def preprocess(self, source, name, filename=None):
142149
return self.preprocessor(source)
143150

144151

145152
class WhitespaceExtension(Extension):
146-
147153
def __init__(self, environment):
148154
super(WhitespaceExtension, self).__init__(environment)
149155
block_start_string = environment.block_start_string
150156
block_end_string = environment.block_end_string
151-
self.preprocessor = WhitespacePreprocessor(rules=[
152-
(re.compile(r'^ \s+|\s+$', re.MULTILINE),
153-
r''),
154-
(re.compile(r'>\s+<'),
155-
r'><'),
156-
(re.compile(
157-
r'>\s+\{%'.replace( # noqa: W605
158-
'\{%', re.escape(block_start_string))), # noqa: W605
159-
r'>{%'.replace('{%', block_start_string)),
160-
(re.compile(
161-
r'%\}\s+<'.replace( # noqa: W605
162-
'%\}', re.escape(block_end_string))), # noqa: W605
163-
r'%}<'.replace('%}', block_end_string)),
164-
])
157+
self.preprocessor = WhitespacePreprocessor(
158+
rules=[
159+
(re.compile(r"^ \s+|\s+$", re.MULTILINE), r""),
160+
(re.compile(r">\s+<"), r"><"),
161+
(
162+
re.compile(
163+
r">\s+\{%".replace( # noqa: W605
164+
"\{%", re.escape(block_start_string) # noqa: W605
165+
)
166+
),
167+
r">{%".replace("{%", block_start_string),
168+
),
169+
(
170+
re.compile(
171+
r"%\}\s+<".replace( # noqa: W605
172+
"%\}", re.escape(block_end_string) # noqa: W605
173+
)
174+
),
175+
r"%}<".replace("%}", block_end_string),
176+
),
177+
]
178+
)
165179

166180
def preprocess(self, source, name, filename=None):
167181
return self.preprocessor(source)
168182

169183

170-
RE_INLINE = re.compile(r'{%\s*inline\s+("|\')(?P<path>.+?)\1\s*%}',
171-
re.MULTILINE)
184+
RE_INLINE = re.compile(
185+
r'{%\s*inline\s+("|\')(?P<path>.+?)\1\s*%}', re.MULTILINE
186+
)
172187

173188

174189
class InlineExtension(Extension):
@@ -188,10 +203,10 @@ class InlineExtension(Extension):
188203
"""
189204

190205
def __init__(self, searchpath, fallback=False):
191-
strategy = fallback and (
192-
lambda path: '{% include "' + path + '" %}') or None
193-
self.preprocessor = InlinePreprocessor(
194-
RE_INLINE, searchpath, strategy)
206+
strategy = (
207+
fallback and (lambda path: '{% include "' + path + '" %}') or None
208+
)
209+
self.preprocessor = InlinePreprocessor(RE_INLINE, searchpath, strategy)
195210

196211
def __call__(self, environment): # pragma: nocover
197212
super(InlineExtension, self).__init__(environment)

0 commit comments

Comments
 (0)