From ee0a7af3128529206da628a9ac217fe81d9dd877 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 7 Mar 2023 14:15:44 -0500 Subject: [PATCH] chore: switch to ruff Signed-off-by: Henry Schreiner --- .pre-commit-config.yaml | 18 ++------- pyproject.toml | 42 +++++++++++++++++++- scripts/convert_to_generic_platform_wheel.py | 9 ++--- scripts/update_ninja_version.py | 21 +++++----- setup.cfg | 11 ----- src/ninja/__init__.py | 4 +- tests/test_ninja.py | 2 +- 7 files changed, 60 insertions(+), 47 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 682e0cf..b57ec5d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 7f6c2ea..6af9975 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/scripts/convert_to_generic_platform_wheel.py b/scripts/convert_to_generic_platform_wheel.py index d9d2c51..7296d73 100644 --- a/scripts/convert_to_generic_platform_wheel.py +++ b/scripts/convert_to_generic_platform_wheel.py @@ -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 @@ -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: @@ -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) @@ -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) diff --git a/scripts/update_ninja_version.py b/scripts/update_ninja_version.py index 341d47d..ab32ea6 100644 --- a/scripts/update_ninja_version.py +++ b/scripts/update_ninja_version.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Command line executable allowing to update NinjaUrls.cmake, documentation @@ -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): diff --git a/setup.cfg b/setup.cfg index a6e048f..1907bd2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/src/ninja/__init__.py b/src/ninja/__init__.py index 8d93a7e..d2c3a24 100644 --- a/src/ninja/__init__.py +++ b/src/ninja/__init__.py @@ -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( diff --git a/tests/test_ninja.py b/tests/test_ninja.py index c526505..1f6aaa9 100644 --- a/tests/test_ninja.py +++ b/tests/test_ninja.py @@ -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():