From 2c3cce8ffdb107e31ccb48ff6f8bded2180377f3 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 23 Oct 2024 09:36:18 +0200 Subject: [PATCH] Format and lint Python code with ruff --- .github/workflows/lint_python.yml | 15 +++++-------- supported_wheels.py | 36 +++++++++++++++++-------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 5fcc7bc3..f3aa5c8a 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -7,18 +7,13 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.12' + python-version: '3.13' - run: pip install --upgrade pip wheel setuptools - - run: pip install bandit black codespell flake8 flake8-2020 flake8-bugbear - flake8-comprehensions isort mypy pytest pyupgrade - - run: bandit --recursive --skip B101 . # B101 is assert statements - - run: black --check . || true - - run: codespell --ignore-words-list="commend" # --skip="*.css,*.js,*.lock" - - run: flake8 . --count --max-complexity=10 --max-line-length=88 - --show-source --statistics - - run: isort --check-only --profile black . + - run: pip install codespell mypy pytest ruff + - run: codespell --ignore-words-list="commend" + - run: ruff format --check + - run: ruff check --output-format=github --select=ALL - run: pip install -r requirements.txt || pip install --editable . || true - run: mkdir --parents --verbose .mypy_cache - run: mypy --ignore-missing-imports --install-types --non-interactive . - run: pytest . || pytest --doctest-modules . || true - - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true diff --git a/supported_wheels.py b/supported_wheels.py index cdec034a..0cb5a9dd 100755 --- a/supported_wheels.py +++ b/supported_wheels.py @@ -1,39 +1,43 @@ #!/usr/bin/env python -""" Filter out wheel filenames not supported on this platform -""" -from __future__ import print_function +"""Filter out wheel filenames not supported on this platform.""" + +from __future__ import annotations import sys from os.path import basename +from typing import TYPE_CHECKING from packaging.tags import sys_tags +if TYPE_CHECKING: + from collections.abc import Iterator + try: - from wheel.install import WHEEL_INFO_RE as wheel_matcher + from wheel.install import WHEEL_INFO_RE as wheel_matcher # noqa: N811 except ImportError: # As of Wheel 0.32.0 from wheel.wheelfile import WHEEL_INFO_RE + wheel_matcher = WHEEL_INFO_RE.match -def tags_for(fname): - # Copied from WheelFile code - parsed_filename = wheel_matcher(basename(fname)) +def tags_for(fname: str) -> Iterator[tuple[str, str, str]]: + """Copied from WheelFile code.""" # noqa: D401 + parsed_filename = wheel_matcher(basename(fname)) # noqa: PTH119 tags = parsed_filename.groupdict() - for pyver in tags['pyver'].split('.'): - for abi in tags['abi'].split('.'): - for plat in tags['plat'].split('.'): + for pyver in tags["pyver"].split("."): + for abi in tags["abi"].split("."): + for plat in tags["plat"].split("."): yield (pyver, abi, plat) -def main(): - supported = { - (tag.interpreter, tag.abi, tag.platform) for tag in sys_tags() - } +def main() -> None: + """Print filenames of all supported wheels.""" + supported = {(tag.interpreter, tag.abi, tag.platform) for tag in sys_tags()} for fname in sys.argv[1:]: tags = set(tags_for(fname)) if supported.intersection(tags): - print(fname) + print(fname) # noqa: T201 -if __name__ == '__main__': +if __name__ == "__main__": main()