Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add black and pyproject configs #796

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: pip install --user ruff
- run: ruff --extend-select=C4,C9,I,PLC,PLE,PLR,U --format=github
--ignore=C414,I001,UP032 --target-version=py37 .
- run: ruff --extend-select=C4,C9,I,PLC,PLE,PLR,U --ignore=C414,I001,UP032 --target-version=py37 .
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
Expand Down
30 changes: 17 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@
extensions = []

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'django-pipeline'
copyright = '2011-2014, Timothée Peignier'
project = "django-pipeline"
copyright = "2011-2014, Timothée Peignier"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -61,7 +61,7 @@

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

# The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None
Expand All @@ -78,7 +78,7 @@
# show_authors = False

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

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -88,7 +88,7 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -161,7 +161,7 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'django-pipelinedoc'
htmlhelp_basename = "django-pipelinedoc"


# -- Options for LaTeX output --------------------------------------------------
Expand All @@ -175,8 +175,13 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'django-pipeline.tex', 'Pipeline Documentation',
'Timothée Peignier', 'manual'),
(
"index",
"django-pipeline.tex",
"Pipeline Documentation",
"Timothée Peignier",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -208,6 +213,5 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'django-pipeline', 'Pipeline Documentation',
['Timothée Peignier'], 1)
("index", "django-pipeline", "Pipeline Documentation", ["Timothée Peignier"], 1)
]
14 changes: 8 additions & 6 deletions pipeline/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ def collect(self, request=None, files=[]):
# Ignore our finder to avoid looping
if isinstance(finder, PipelineFinder):
continue
for path, storage in finder.list(['CVS', '.*', '*~']):
for path, storage in finder.list(["CVS", ".*", "*~"]):
# Prefix the relative path if the source storage contains it
if getattr(storage, 'prefix', None):
if getattr(storage, "prefix", None):
prefixed_path = os.path.join(storage.prefix, path)
else:
prefixed_path = path

if (prefixed_path not in found_files and
(not files or prefixed_path in files)):
if prefixed_path not in found_files and (
not files or prefixed_path in files
):
found_files[prefixed_path] = (storage, path)
self.copy_file(path, prefixed_path, storage)

Expand Down Expand Up @@ -82,8 +83,9 @@ def delete_file(self, path, prefixed_path, source_storage):
else:
# Skip the file if the source file is younger
# Avoid sub-second precision
if (target_last_modified.replace(microsecond=0)
>= source_last_modified.replace(microsecond=0)):
if target_last_modified.replace(
microsecond=0
) >= source_last_modified.replace(microsecond=0):
return False
# Then delete the existing file if really needed
self.storage.delete(prefixed_path)
Expand Down
31 changes: 17 additions & 14 deletions pipeline/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
project_infile = finders.find(input_path)
outfile = compiler.output_path(infile, compiler.output_extension)
outdated = compiler.is_outdated(project_infile, outfile)
compiler.compile_file(project_infile, outfile,
outdated=outdated, force=force,
**compiler_options)
compiler.compile_file(
project_infile,
outfile,
outdated=outdated,
force=force,
**compiler_options,
)

return compiler.output_path(input_path, compiler.output_extension)
else:
Expand Down Expand Up @@ -71,14 +75,14 @@
return self.storage.save(path, ContentFile(content))

def read_file(self, path):
file = self.storage.open(path, 'rb')
file = self.storage.open(path, "rb")

Check warning on line 78 in pipeline/compilers/__init__.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/__init__.py#L78

Added line #L78 was not covered by tests
content = file.read()
file.close()
return content

def output_path(self, path, extension):
path = os.path.splitext(path)
return '.'.join((path[0], extension))
return ".".join((path[0], extension))

def is_outdated(self, infile, outfile):
if not os.path.exists(outfile):
Expand Down Expand Up @@ -125,12 +129,11 @@
cwd or os.path.dirname(stdout_captured or "") or os.getcwd()
)
with NamedTemporaryFile(
'wb', delete=False, dir=temp_file_container
"wb", delete=False, dir=temp_file_container
) as stdout:
compiling = subprocess.Popen(argument_list,
cwd=cwd,
stdout=stdout,
stderr=subprocess.PIPE)
compiling = subprocess.Popen(
argument_list, cwd=cwd, stdout=stdout, stderr=subprocess.PIPE
)
_, stderr = compiling.communicate()
set_std_streams_blocking()

Expand All @@ -139,17 +142,17 @@
raise CompilerError(
f"{argument_list!r} exit code {compiling.returncode}\n{stderr}",
command=argument_list,
error_output=force_str(stderr))
error_output=force_str(stderr),
)

# User wants to see everything that happened.
if self.verbose:
with open(stdout.name, 'rb') as out:
with open(stdout.name, "rb") as out:

Check warning on line 150 in pipeline/compilers/__init__.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/__init__.py#L150

Added line #L150 was not covered by tests
print(out.read())
print(stderr)
except OSError as e:
stdout_captured = None # Don't save erroneous result.
raise CompilerError(e, command=argument_list,
error_output=str(e))
raise CompilerError(e, command=argument_list, error_output=str(e))
finally:
# Decide what to do with captured stdout.
if stdout:
Expand Down
4 changes: 2 additions & 2 deletions pipeline/compilers/coffee.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


class CoffeeScriptCompiler(SubProcessCompiler):
output_extension = 'js'
output_extension = "js"

def match_file(self, path):
return path.endswith('.coffee') or path.endswith('.litcoffee')
return path.endswith(".coffee") or path.endswith(".litcoffee")

Check warning on line 9 in pipeline/compilers/coffee.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/coffee.py#L9

Added line #L9 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
Expand Down
6 changes: 3 additions & 3 deletions pipeline/compilers/es6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


class ES6Compiler(SubProcessCompiler):
output_extension = 'js'
output_extension = "js"

def match_file(self, path):
return path.endswith('.es6')
return path.endswith(".es6")

Check warning on line 9 in pipeline/compilers/es6.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/es6.py#L9

Added line #L9 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
Expand All @@ -16,6 +16,6 @@
settings.BABEL_ARGUMENTS,
infile,
"-o",
outfile
outfile,
)
return self.execute_command(command)
4 changes: 2 additions & 2 deletions pipeline/compilers/less.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


class LessCompiler(SubProcessCompiler):
output_extension = 'css'
output_extension = "css"

def match_file(self, filename):
return filename.endswith('.less')
return filename.endswith(".less")

Check warning on line 11 in pipeline/compilers/less.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/less.py#L11

Added line #L11 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
# Pipe to file rather than provide outfile arg due to a bug in lessc
Expand Down
4 changes: 2 additions & 2 deletions pipeline/compilers/livescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


class LiveScriptCompiler(SubProcessCompiler):
output_extension = 'js'
output_extension = "js"

def match_file(self, path):
return path.endswith('.ls')
return path.endswith(".ls")

Check warning on line 9 in pipeline/compilers/livescript.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/livescript.py#L9

Added line #L9 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
Expand Down
11 changes: 3 additions & 8 deletions pipeline/compilers/sass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@


class SASSCompiler(SubProcessCompiler):
output_extension = 'css'
output_extension = "css"

def match_file(self, filename):
return filename.endswith(('.scss', '.sass'))
return filename.endswith((".scss", ".sass"))

Check warning on line 11 in pipeline/compilers/sass.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/sass.py#L11

Added line #L11 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
command = (
settings.SASS_BINARY,
settings.SASS_ARGUMENTS,
infile,
outfile
)
command = (settings.SASS_BINARY, settings.SASS_ARGUMENTS, infile, outfile)
return self.execute_command(command, cwd=dirname(infile))
10 changes: 3 additions & 7 deletions pipeline/compilers/stylus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@


class StylusCompiler(SubProcessCompiler):
output_extension = 'css'
output_extension = "css"

def match_file(self, filename):
return filename.endswith('.styl')
return filename.endswith(".styl")

Check warning on line 11 in pipeline/compilers/stylus.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/stylus.py#L11

Added line #L11 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
command = (
settings.STYLUS_BINARY,
settings.STYLUS_ARGUMENTS,
infile
)
command = (settings.STYLUS_BINARY, settings.STYLUS_ARGUMENTS, infile)
return self.execute_command(command, cwd=dirname(infile))
6 changes: 3 additions & 3 deletions pipeline/compilers/typescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


class TypeScriptCompiler(SubProcessCompiler):
output_extension = 'js'
output_extension = "js"

def match_file(self, path):
return path.endswith('.ts')
return path.endswith(".ts")

Check warning on line 9 in pipeline/compilers/typescript.py

View check run for this annotation

Codecov / codecov/patch

pipeline/compilers/typescript.py#L9

Added line #L9 was not covered by tests

def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
Expand All @@ -15,7 +15,7 @@
settings.TYPE_SCRIPT_BINARY,
settings.TYPE_SCRIPT_ARGUMENTS,
infile,
'--outFile',
"--outFile",
outfile,
)
return self.execute_command(command)
Loading
Loading