Skip to content

Commit 52b8024

Browse files
authored
Fix issues raised by flake8 (#779)
1 parent a642568 commit 52b8024

23 files changed

+423
-190
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
[flake8]
12
max-line-length = 88
3+
exclude =
4+
.tox
5+
node_modules
6+
*env/

docs/conf.py

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Pipeline documentation build configuration file, created by
42
# sphinx-quickstart on Sat Apr 30 17:47:55 2011.
53
#
@@ -15,12 +13,12 @@
1513
# If extensions (or modules to document with autodoc) are in another directory,
1614
# add these directories to sys.path here. If the directory is relative to the
1715
# documentation root, use os.path.abspath to make it absolute, like shown here.
18-
#sys.path.insert(0, os.path.abspath('.'))
16+
# sys.path.insert(0, os.path.abspath('.'))
1917

2018
# -- General configuration -----------------------------------------------------
2119

2220
# If your documentation needs a minimal Sphinx version, state it here.
23-
#needs_sphinx = '1.0'
21+
# needs_sphinx = '1.0'
2422

2523
# Add any Sphinx extension module names here, as strings. They can be extensions
2624
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
@@ -33,7 +31,7 @@
3331
source_suffix = '.rst'
3432

3533
# The encoding of source files.
36-
#source_encoding = 'utf-8-sig'
34+
# source_encoding = 'utf-8-sig'
3735

3836
# The master toctree document.
3937
master_doc = 'index'
@@ -53,37 +51,37 @@
5351

5452
# The language for content autogenerated by Sphinx. Refer to documentation
5553
# for a list of supported languages.
56-
#language = None
54+
# language = None
5755

5856
# There are two options for replacing |today|: either, you set today to some
5957
# non-false value, then it is used:
60-
#today = ''
58+
# today = ''
6159
# Else, today_fmt is used as the format for a strftime call.
62-
#today_fmt = '%B %d, %Y'
60+
# today_fmt = '%B %d, %Y'
6361

6462
# List of patterns, relative to source directory, that match files and
6563
# directories to ignore when looking for source files.
6664
exclude_patterns = ['_build']
6765

6866
# The reST default role (used for this markup: `text`) to use for all documents.
69-
#default_role = None
67+
# default_role = None
7068

7169
# If true, '()' will be appended to :func: etc. cross-reference text.
72-
#add_function_parentheses = True
70+
# add_function_parentheses = True
7371

7472
# If true, the current module name will be prepended to all description
7573
# unit titles (such as .. function::).
76-
#add_module_names = True
74+
# add_module_names = True
7775

7876
# If true, sectionauthor and moduleauthor directives will be shown in the
7977
# output. They are ignored by default.
80-
#show_authors = False
78+
# show_authors = False
8179

8280
# The name of the Pygments (syntax highlighting) style to use.
8381
pygments_style = 'sphinx'
8482

8583
# A list of ignored prefixes for module index sorting.
86-
#modindex_common_prefix = []
84+
# modindex_common_prefix = []
8785

8886

8987
# -- Options for HTML output ---------------------------------------------------
@@ -95,72 +93,72 @@
9593
# Theme options are theme-specific and customize the look and feel of a theme
9694
# further. For a list of options available for each theme, see the
9795
# documentation.
98-
#html_theme_options = {}
96+
# html_theme_options = {}
9997

10098
# Add any paths that contain custom themes here, relative to this directory.
101-
#html_theme_path = []
99+
# html_theme_path = []
102100

103101
# The name for this set of Sphinx documents. If None, it defaults to
104102
# "<project> v<release> documentation".
105-
#html_title = None
103+
# html_title = None
106104

107105
# A shorter title for the navigation bar. Default is the same as html_title.
108-
#html_short_title = None
106+
# html_short_title = None
109107

110108
# The name of an image file (relative to this directory) to place at the top
111109
# of the sidebar.
112-
#html_logo = None
110+
# html_logo = None
113111

114112
# The name of an image file (within the static path) to use as favicon of the
115113
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
116114
# pixels large.
117-
#html_favicon = None
115+
# html_favicon = None
118116

119117
# Add any paths that contain custom static files (such as style sheets) here,
120118
# relative to this directory. They are copied after the builtin static files,
121119
# so a file named "default.css" will overwrite the builtin "default.css".
122-
#html_static_path = ['_static']
120+
# html_static_path = ['_static']
123121

124122
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
125123
# using the given strftime format.
126-
#html_last_updated_fmt = '%b %d, %Y'
124+
# html_last_updated_fmt = '%b %d, %Y'
127125

128126
# If true, SmartyPants will be used to convert quotes and dashes to
129127
# typographically correct entities.
130-
#html_use_smartypants = True
128+
# html_use_smartypants = True
131129

132130
# Custom sidebar templates, maps document names to template names.
133-
#html_sidebars = {}
131+
# html_sidebars = {}
134132

135133
# Additional templates that should be rendered to pages, maps page names to
136134
# template names.
137-
#html_additional_pages = {}
135+
# html_additional_pages = {}
138136

139137
# If false, no module index is generated.
140-
#html_domain_indices = True
138+
# html_domain_indices = True
141139

142140
# If false, no index is generated.
143-
#html_use_index = True
141+
# html_use_index = True
144142

145143
# If true, the index is split into individual pages for each letter.
146-
#html_split_index = False
144+
# html_split_index = False
147145

148146
# If true, links to the reST sources are added to the pages.
149-
#html_show_sourcelink = True
147+
# html_show_sourcelink = True
150148

151149
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
152-
#html_show_sphinx = True
150+
# html_show_sphinx = True
153151

154152
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
155-
#html_show_copyright = True
153+
# html_show_copyright = True
156154

157155
# If true, an OpenSearch description file will be output, and all pages will
158156
# contain a <link> tag referring to it. The value of this option must be the
159157
# base URL from which the finished HTML is served.
160-
#html_use_opensearch = ''
158+
# html_use_opensearch = ''
161159

162160
# This is the file name suffix for HTML files (e.g. ".xhtml").
163-
#html_file_suffix = None
161+
# html_file_suffix = None
164162

165163
# Output file base name for HTML help builder.
166164
htmlhelp_basename = 'django-pipelinedoc'
@@ -169,10 +167,10 @@
169167
# -- Options for LaTeX output --------------------------------------------------
170168

171169
# The paper size ('letter' or 'a4').
172-
#latex_paper_size = 'letter'
170+
# latex_paper_size = 'letter'
173171

174172
# The font size ('10pt', '11pt' or '12pt').
175-
#latex_font_size = '10pt'
173+
# latex_font_size = '10pt'
176174

177175
# Grouping the document tree into LaTeX files. List of tuples
178176
# (source start file, target name, title, author, documentclass [howto/manual]).
@@ -183,26 +181,26 @@
183181

184182
# The name of an image file (relative to this directory) to place at the top of
185183
# the title page.
186-
#latex_logo = None
184+
# latex_logo = None
187185

188186
# For "manual" documents, if this is true, then toplevel headings are parts,
189187
# not chapters.
190-
#latex_use_parts = False
188+
# latex_use_parts = False
191189

192190
# If true, show page references after internal links.
193-
#latex_show_pagerefs = False
191+
# latex_show_pagerefs = False
194192

195193
# If true, show URL addresses after external links.
196-
#latex_show_urls = False
194+
# latex_show_urls = False
197195

198196
# Additional stuff for the LaTeX preamble.
199-
#latex_preamble = ''
197+
# latex_preamble = ''
200198

201199
# Documents to append as an appendix to all manuals.
202-
#latex_appendices = []
200+
# latex_appendices = []
203201

204202
# If false, no module index is generated.
205-
#latex_domain_indices = True
203+
# latex_domain_indices = True
206204

207205

208206
# -- Options for manual page output --------------------------------------------

pipeline/collector.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def collect(self, request=None, files=[]):
4646
prefixed_path = path
4747

4848
if (prefixed_path not in found_files and
49-
(not files or prefixed_path in files)):
49+
(not files or prefixed_path in files)):
5050
found_files[prefixed_path] = (storage, path)
5151
self.copy_file(path, prefixed_path, storage)
5252

@@ -67,7 +67,10 @@ def delete_file(self, path, prefixed_path, source_storage):
6767
if self.storage.exists(prefixed_path):
6868
try:
6969
# When was the target file modified last time?
70-
target_last_modified = self._get_modified_time(self.storage, prefixed_path)
70+
target_last_modified = self._get_modified_time(
71+
self.storage,
72+
prefixed_path,
73+
)
7174
except (OSError, NotImplementedError, AttributeError):
7275
# The storage doesn't support ``modified_time`` or failed
7376
pass
@@ -82,9 +85,10 @@ def delete_file(self, path, prefixed_path, source_storage):
8285
# Avoid sub-second precision
8386
if (target_last_modified.replace(microsecond=0)
8487
>= source_last_modified.replace(microsecond=0)):
85-
return False
88+
return False
8689
# Then delete the existing file if really needed
8790
self.storage.delete(prefixed_path)
8891
return True
8992

93+
9094
default_collector = Collector()

pipeline/compilers/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def _compile(input_path):
5050
except ImportError:
5151
return list(map(_compile, paths))
5252
else:
53-
with futures.ThreadPoolExecutor(max_workers=multiprocessing.cpu_count()) as executor:
53+
with futures.ThreadPoolExecutor(
54+
max_workers=multiprocessing.cpu_count()
55+
) as executor:
5456
return list(executor.map(_compile, paths))
5557

5658

@@ -112,14 +114,19 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
112114
else:
113115
argument_list.extend(flattening_arg)
114116

115-
# The first element in argument_list is the program that will be executed; if it is '', then
116-
# a PermissionError will be raised. Thus empty arguments are filtered out from argument_list
117+
# The first element in argument_list is the program that will be
118+
# executed; if it is '', then a PermissionError will be raised.
119+
# Thus empty arguments are filtered out from argument_list
117120
argument_list = list(filter(None, argument_list))
118121
stdout = None
119122
try:
120123
# We always catch stdout in a file, but we may not have a use for it.
121-
temp_file_container = cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
122-
with NamedTemporaryFile('wb', delete=False, dir=temp_file_container) as stdout:
124+
temp_file_container = (
125+
cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
126+
)
127+
with NamedTemporaryFile(
128+
'wb', delete=False, dir=temp_file_container
129+
) as stdout:
123130
compiling = subprocess.Popen(argument_list,
124131
cwd=cwd,
125132
stdout=stdout,
@@ -147,6 +154,8 @@ def execute_command(self, command, cwd=None, stdout_captured=None):
147154
# Decide what to do with captured stdout.
148155
if stdout:
149156
if stdout_captured:
150-
shutil.move(stdout.name, os.path.join(cwd or os.curdir, stdout_captured))
157+
shutil.move(
158+
stdout.name, os.path.join(cwd or os.curdir, stdout_captured)
159+
)
151160
else:
152161
os.remove(stdout.name)

pipeline/compilers/less.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ def compile_file(self, infile, outfile, outdated=False, force=False):
1717
settings.LESS_ARGUMENTS,
1818
infile,
1919
)
20-
return self.execute_command(command, cwd=dirname(infile), stdout_captured=outfile)
20+
return self.execute_command(
21+
command, cwd=dirname(infile), stdout_captured=outfile
22+
)

pipeline/compressors/__init__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
NON_REWRITABLE_URL = re.compile(r'^(#|http:|https:|data:|//)')
1818

1919
DEFAULT_TEMPLATE_FUNC = "template"
20-
TEMPLATE_FUNC = r"""var template = function(str){var fn = new Function('obj', 'var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(\''+str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/<%=([\s\S]+?)%>/g,function(match,code){return "',"+code.replace(/\\'/g, "'")+",'";}).replace(/<%([\s\S]+?)%>/g,function(match,code){return "');"+code.replace(/\\'/g, "'").replace(/[\r\n\t]/g,' ')+"__p.push('";}).replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+"');}return __p.join('');");return fn;};"""
20+
TEMPLATE_FUNC = r"""var template = function(str){var fn = new Function('obj', 'var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(\''+str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/<%=([\s\S]+?)%>/g,function(match,code){return "',"+code.replace(/\\'/g, "'")+",'";}).replace(/<%([\s\S]+?)%>/g,function(match,code){return "');"+code.replace(/\\'/g, "'").replace(/[\r\n\t]/g,' ')+"__p.push('";}).replace(/\r/g,'\\r').replace(/\n/g,'\\n').replace(/\t/g,'\\t')+"');}return __p.join('');");return fn;};""" # noqa
2121

2222
MIME_TYPES = {
2323
'.png': 'image/png',
@@ -96,7 +96,10 @@ def compile_templates(self, paths):
9696
settings.TEMPLATE_FUNC,
9797
contents
9898
))
99-
compiler = TEMPLATE_FUNC if settings.TEMPLATE_FUNC == DEFAULT_TEMPLATE_FUNC else ""
99+
if settings.TEMPLATE_FUNC == DEFAULT_TEMPLATE_FUNC:
100+
compiler = TEMPLATE_FUNC
101+
else:
102+
compiler = ""
100103
return "\n".join([
101104
"%(namespace)s = %(namespace)s || {};" % {'namespace': namespace},
102105
compiler,
@@ -148,7 +151,10 @@ def concatenate(self, paths):
148151

149152
def construct_asset_path(self, asset_path, css_path, output_filename, variant=None):
150153
"""Return a rewritten asset URL for a stylesheet"""
151-
public_path = self.absolute_path(asset_path, os.path.dirname(css_path).replace('\\', '/'))
154+
public_path = self.absolute_path(
155+
asset_path,
156+
os.path.dirname(css_path).replace('\\', '/'),
157+
)
152158
if self.embeddable(public_path, variant):
153159
return "__EMBED__%s" % public_path
154160
if not posixpath.isabs(asset_path):
@@ -161,11 +167,13 @@ def embeddable(self, path, variant):
161167
font = ext in FONT_EXTS
162168
if not variant:
163169
return False
164-
if not (re.search(settings.EMBED_PATH, path.replace('\\', '/')) and self.storage.exists(path)):
170+
if not (re.search(settings.EMBED_PATH, path.replace('\\', '/'))
171+
and self.storage.exists(path)):
165172
return False
166173
if ext not in EMBED_EXTS:
167174
return False
168-
if not (font or len(self.encoded_content(path)) < settings.EMBED_MAX_IMAGE_SIZE):
175+
if not (font or
176+
len(self.encoded_content(path)) < settings.EMBED_MAX_IMAGE_SIZE):
169177
return False
170178
return True
171179

@@ -204,7 +212,8 @@ def absolute_path(self, path, start):
204212
def relative_path(self, absolute_path, output_filename):
205213
"""Rewrite paths relative to the output stylesheet path"""
206214
absolute_path = posixpath.join(settings.PIPELINE_ROOT, absolute_path)
207-
output_path = posixpath.join(settings.PIPELINE_ROOT, posixpath.dirname(output_filename))
215+
output_path = posixpath.join(
216+
settings.PIPELINE_ROOT, posixpath.dirname(output_filename))
208217
return relpath(absolute_path, output_path)
209218

210219
def read_bytes(self, path):

pipeline/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
'UGLIFYJS_BINARY': '/usr/bin/env uglifyjs',
4949
'UGLIFYJS_ARGUMENTS': '',
50-
50+
5151
'TERSER_BINARY': '/usr/bin/env terser',
5252
'TERSER_ARGUMENTS': '--compress',
5353

pipeline/forms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ def _get_media_files(cls, packager, media_packages, media_type,
214214
"""
215215
source_files = list(extra_files)
216216

217-
if (not settings.PIPELINE_ENABLED and
218-
settings.PIPELINE_COLLECTOR_ENABLED):
217+
if (not settings.PIPELINE_ENABLED and settings.PIPELINE_COLLECTOR_ENABLED):
219218
default_collector.collect()
220219

221220
for media_package in media_packages:

0 commit comments

Comments
 (0)