From 21fcd8960f1dae5ec4563dd99860d0918efe5cff Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 19 Oct 2023 05:40:41 -0400 Subject: [PATCH] Use Ruff for `from __future__ import annotations` checks (#10910) --- .github/workflows/tests.yml | 9 +++++++++ .pre-commit-config.yaml | 4 ++-- pyproject.toml | 9 ++++++--- requirements-tests.txt | 2 +- tests/check_consistent.py | 3 --- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 17397ddde..75603ab30 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,6 +45,15 @@ jobs: python-version: "3.11" - run: ./tests/check_new_syntax.py + ruff: + name: Lint with Ruff + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 + with: + version: "0.1.0" # must match .pre-commit-config.yaml and requirements-test.txt + flake8: name: Lint with Flake8 runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4e4f6ab4..16307ab80 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,10 +20,10 @@ repos: - id: isort name: isort (python) - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.0 # must match requirements-tests.txt + rev: v0.1.0 # must match requirements-tests.txt and tests.yml hooks: - id: ruff - args: [--exit-non-zero-on-fix] + args: [--exit-non-zero-on-fix, --fix-only] - repo: https://github.com/pycqa/flake8 rev: 6.1.0 # must match requirements-tests.txt hooks: diff --git a/pyproject.toml b/pyproject.toml index 7c017bb2f..6a7ae3e93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,15 +60,17 @@ known_first_party = ["parse_metadata", "utils"] [tool.ruff] line-length = 130 +# Oldest supported Python version target-version = "py37" fix = true exclude = [ - # We're only interested in autofixes for our stubs - "*.py", # Ignore generated protobuf stubs "*_pb2.pyi", - # virtual environment, cache directories, etc.: + # virtual environment ".env", + ".venv", + "env", + # cache directories, etc.: ".git", ".mypy_cache", ".pytype", @@ -80,6 +82,7 @@ exclude = [ # only enable rules that are relevant to stubs select = [ "F401", # Remove unused imports + "FA", # flake8-future-annotations "PYI009", # use `...`, not `pass`, in empty class bodies "PYI010", # function bodies must be empty "PYI012", # class bodies must not contain `pass` diff --git a/requirements-tests.txt b/requirements-tests.txt index 1586ecd99..9201a41d6 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -10,7 +10,7 @@ isort==5.12.0 # must match .pre-commit-config.yaml mypy==1.6.1 pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml pytype==2023.10.17; platform_system != "Windows" and python_version < "3.12" -ruff==0.1.0 # must match .pre-commit-config.yaml +ruff==0.1.0 # must match .pre-commit-config.yaml and tests.yml # Libraries used by our various scripts. aiohttp==3.8.5; python_version < "3.12" # aiohttp can't be installed on 3.12 yet diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 004dbbbbf..91fdf68bd 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -83,9 +83,6 @@ def check_test_cases() -> None: bad_test_case_filename = 'Files in a `test_cases` directory must have names starting with "check_"; got "{}"' for file in testcase_dir.rglob("*.py"): assert file.stem.startswith("check_"), bad_test_case_filename.format(file) - with open(file, encoding="UTF-8") as f: - lines = {line.strip() for line in f} - assert "from __future__ import annotations" in lines, "Test-case files should use modern typing syntax where possible" def check_no_symlinks() -> None: