Skip to content

chore: switch to ruff #174

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

Merged
merged 1 commit into from
Mar 11, 2023
Merged
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
18 changes: 4 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ repos:
- id: trailing-whitespace
- id: fix-encoding-pragma

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.253"
hooks:
- id: isort

- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
hooks:
- id: pyupgrade

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
- id: ruff
args: [--fix, --show-fixes]
42 changes: 40 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,43 @@ before-all = [
select = "*-musllinux_*"
environment = { LDFLAGS = "-static-libstdc++ -static-libgcc" }

[tool.isort]
profile = "black"

[tool.ruff]
select = [
"E", "F", "W", # flake8
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
extend-ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
"RUF005", # Python 3 needed
"B904", # Python 3 needed
# "SIM105", # Python 3 needed
]
src = ["src"]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
exclude = ["versioneer.py", "src/ninja/version.py"]
flake8-unused-arguments.ignore-variadic-names = true

[tool.ruff.per-file-ignores]
"*.pyi" = ["ARG001"]
"noxfile.py" = ["PLW0603"] # Could be fixed if Python 2 dropped
9 changes: 4 additions & 5 deletions scripts/convert_to_generic_platform_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import os
import sys
from itertools import product
from os.path import abspath, basename, dirname, isfile
from os.path import abspath, basename, dirname, isfile, splitext
from os.path import join as pjoin
from os.path import splitext

try:
from wheel.install import WheelFile
Expand Down Expand Up @@ -78,7 +77,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms)
platform_tags = fparts['plat'].split('.')
logger.debug('Previous platform tags: %s', ', '.join(platform_tags))
if additional_platforms:
platform_tags = list(sorted(set(platform_tags + [p for p in additional_platforms])))
platform_tags = sorted(set(platform_tags + list(additional_platforms)))
fparts['plat'] = '.'.join(platform_tags)
logger.debug('New platform tags ....: %s', ', '.join(platform_tags))
else:
Expand All @@ -98,7 +97,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx, py2_py3, additional_platforms)
if py2_py3:
if len({"py2", "py3"} & set(pyver_tags)) == 0:
raise ValueError("pyver_tags does not contain py2 nor py3")
pyver_tags = list(sorted(set(pyver_tags + ["py2", "py3"])))
pyver_tags = sorted(set(pyver_tags + ["py2", "py3"]))
if pyver_tags != original_pyver_tags:
logger.debug('New pyver tags ....: %s', ', '.join(pyver_tags))
fparts['pyver'] = '.'.join(pyver_tags)
Expand Down Expand Up @@ -160,7 +159,7 @@ def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_orig
ctx.out_wheel = _convert_to_generic_platform_wheel(ctx, py2_py3, additional_platforms)

if remove_original:
logger.info('Removed original wheel %s' % wheel_path)
logger.info('Removed original wheel %s', wheel_path)
os.remove(wheel_path)


Expand Down
21 changes: 9 additions & 12 deletions scripts/update_ninja_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Command line executable allowing to update NinjaUrls.cmake, documentation
Expand Down Expand Up @@ -101,19 +100,17 @@ def generate_cmake_variables(urls_and_sha256s):
template_inputs["%s_url" % var_prefix] = urls_and_sha256s_values[0]
template_inputs["%s_sha256" % var_prefix] = urls_and_sha256s_values[1]

cmake_variables = textwrap.dedent(
return textwrap.dedent(
"""
#-----------------------------------------------------------------------------
# Ninja sources
set(unix_source_url "{unix_source_url}")
set(unix_source_sha256 "{unix_source_sha256}")

set(windows_source_url "{win_source_url}")
set(windows_source_sha256 "{win_source_sha256}")
"""
).format(**template_inputs)
#-----------------------------------------------------------------------------
# Ninja sources
set(unix_source_url "{unix_source_url}")
set(unix_source_sha256 "{unix_source_sha256}")

return cmake_variables
set(windows_source_url "{win_source_url}")
set(windows_source_sha256 "{win_source_sha256}")
"""
).format(**template_inputs)


def update_cmake_urls_script(upstream_repository, version):
Expand Down
11 changes: 0 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
[flake8]
max-line-length: 130
# Whether to display the pep8 instructions on failure (can be quite verbose)
show-pep8: False
# Whether to show source code for each failure
show-source: True
# Maximum cyclomatic complexity allowed
max-complexity: 14
format: pylint
exclude: .git,.idea,.eggs,__pycache__,.tox,_skbuild,Ninja-src,src,versioneer.py,ninja/ninja_syntax.py,_version.py,.venv,.nox

[tool:pytest]
testpaths = tests
addopts = -v --cov --cov-report xml
Expand Down
4 changes: 2 additions & 2 deletions src/ninja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
__all__ = ["__version__", "DATA", "BIN_DIR", "ninja"]


def __dir__(self):
def __dir__():
return __all__


try:
from .ninja_syntax import Writer, escape, expand # noqa: F401
from .ninja_syntax import Writer, escape, expand
except ImportError:
# Support importing `ninja_syntax` from the source tree
if not os.path.exists(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _run(program, args):
args = ["%s.py" % program] + args
with push_argv(args), pytest.raises(SystemExit) as excinfo:
func()
assert 0 == excinfo.value.code
assert excinfo.value.code == 0


def test_ninja_module():
Expand Down