From 0589cf609b56e563ed771d954006d3bb604f64af Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Thu, 31 Oct 2024 16:38:16 +0100 Subject: [PATCH] Simplify linting --- .github/CONTRIBUTING.md | 3 +- .pre-commit-config.yaml | 37 +++-------------- pyproject.toml | 54 +++++++++++++++++++++---- src/_argon2_cffi_bindings/_ffi_build.py | 2 +- tests/test_build.py | 2 +- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d1e2b33..d66fc73 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -119,7 +119,8 @@ $ pre-commit run --all-files """ ``` - If you add or change public APIs, tag the docstring using `.. versionadded:: 16.0.0 WHAT` or `.. versionchanged:: 16.2.0 WHAT`. -- We use [*isort*](https://github.com/PyCQA/isort) to sort our imports, and we use [*Black*](https://github.com/psf/black) with line length of 79 characters to format our code. + +- We use [Ruff](https://ruff.rs/) to sort our imports and format our code with a line length of 79 characters. As long as you run our full [*tox*] suite before committing, or install our [*pre-commit*] hooks (ideally you'll do both – see [*Local Development Environment*](#local-development-environment) above), you won't have to spend any time on formatting your code at all. If you don't, [CI] will catch it for you – but that seems like a waste of your time! diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af63e6d..850c1d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,39 +2,13 @@ ci: autoupdate_schedule: monthly -default_language_version: - python: python3.12 - repos: - - repo: https://github.com/psf/black - rev: 24.10.0 - hooks: - - id: black - language_version: python3.10 - - - repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - additional_dependencies: [toml] - - - repo: https://github.com/asottile/pyupgrade - rev: v3.18.0 - hooks: - - id: pyupgrade - args: [--py37-plus] - - - repo: https://github.com/asottile/yesqa - rev: v1.5.0 - hooks: - - id: yesqa - additional_dependencies: [flake8-bugbear] - - - repo: https://github.com/PyCQA/flake8 - rev: 7.1.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.1 hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear] + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/econchick/interrogate rev: 1.7.0 @@ -46,7 +20,6 @@ repos: rev: v2.3.0 hooks: - id: codespell - args: [-L, alog] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 diff --git a/pyproject.toml b/pyproject.toml index 05a6c7e..07bc4ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,16 +66,54 @@ testpaths = "tests" filterwarnings = ["once::Warning"] -[tool.black] -line-length = 79 - - -[tool.isort] -profile = "attrs" - - [tool.interrogate] omit-covered-files = true verbose = 2 fail-under = 100 whitelist-regex = ["test_.*"] + + +[tool.ruff] +src = ["src", "tests"] +line-length = 79 + +[tool.ruff.lint] +select = ["ALL"] +ignore = [ + "A001", # shadowing is fine + "A002", # shadowing is fine + "A003", # shadowing is fine + "ANN", # Mypy is better at this + "ARG001", # unused arguments are normal when implementing interfaces + "COM", # Formatter takes care of our commas + "D", # We prefer our own docstring style. + "E501", # leave line-length enforcement to formatter + "ERA001", # Dead code detection is overly eager. + "FBT", # we have one function that takes one bool; c'mon! + "FIX", # Yes, we want XXX as a marker. + "INP001", # sometimes we want Python files outside of packages + "ISC001", # conflicts with ruff format + "PLR0913", # yes, many arguments, but most have defaults + "PLR2004", # numbers are sometimes fine + "PLW2901", # re-assigning within loop bodies is fine + "RUF001", # leave my smart characters alone + "SLF001", # private members are accessed by friendly functions + "TCH", # TYPE_CHECKING blocks break autodocs + "TD", # we don't follow other people's todo style +] + +[tool.ruff.lint.per-file-ignores] +"src/argon2/__main__.py" = ["T201"] # need print in CLI +"tests/*" = [ + "ARG", # stubs don't care about arguments + "S101", # assert + "SIM300", # Yoda rocks in asserts + "PT005", # we always add underscores and explicit name + "PT011", # broad is fine + "TRY002", # stock exceptions are fine in tests + "EM101", # no need for exception msg hygiene in tests +] + +[tool.ruff.lint.isort] +lines-between-types = 1 +lines-after-imports = 2 diff --git a/src/_argon2_cffi_bindings/_ffi_build.py b/src/_argon2_cffi_bindings/_ffi_build.py index 0d4d0be..975d682 100644 --- a/src/_argon2_cffi_bindings/_ffi_build.py +++ b/src/_argon2_cffi_bindings/_ffi_build.py @@ -55,7 +55,7 @@ def _get_target_platform(arch_flags, default): "_ffi", "#include ", extra_compile_args=["-msse2"] if (optimized and not windows) else None, - include_dirs=[os.path.join("extras", "libargon2", "include")], + include_dirs=[str(Path("extras", "libargon2", "include"))], sources=[ str(lib_base / path) for path in [ diff --git a/tests/test_build.py b/tests/test_build.py index dedf65d..fe3aaa9 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -4,7 +4,7 @@ @pytest.mark.parametrize( - "arch_flags, expected", + ("arch_flags", "expected"), [ (" -arch arm64", "arm64"), ("abc -arch arm64 xyz", "arm64"),