From e5410febe7c0eac5556036228f02ece9a9e542a7 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 18 Oct 2023 15:35:40 -0400 Subject: [PATCH 1/3] Use Ruff for `from __future__ import annotations` checks --- pyproject.toml | 3 +-- tests/check_consistent.py | 3 --- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 346619c2f119..d98ace93a358 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,8 +63,6 @@ line-length = 130 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.: @@ -79,6 +77,7 @@ exclude = [ # Only enable rules that have safe autofixes; # only enable rules that are relevant to stubs select = [ + "FA", # flake8-future-annotations "F401", # Remove unused imports "UP004", # Remove explicit `object` inheritance "UP006", # PEP-585 autofixes diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 57249f16b104..98befa725750 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: From be0c8bf2ee7e209e78120349bcef6d487a2e6a19 Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 18 Oct 2023 16:06:55 -0400 Subject: [PATCH 2/3] Actually run Ruff check --- .github/workflows/tests.yml | 11 ++++++++++- .pre-commit-config.yaml | 4 ++-- pyproject.toml | 38 +++++++++++++++++++------------------ requirements-tests.txt | 2 +- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ba2fc7ab8ac..8bb998647cec 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,8 +45,17 @@ 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.0.292" # must match .pre-commit-config.yaml and requirements-test.txt + flake8: - name: Lint with flake8 + name: Lint with Flake8 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b63f3b911ab4..4d384ee6f6ef 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.0.292 # must match requirements-tests.txt + rev: v0.0.292 # 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 d98ace93a358..a24ac1755e0e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,15 +60,17 @@ known_first_party = ["utils", "parse_metadata"] [tool.ruff] line-length = 130 +# Oldest supported Python version target-version = "py37" fix = true exclude = [ # Ignore generated protobuf stubs "*_pb2.pyi", - # virtual environment, cache directories, etc.: - "env", + # virtual environment ".env", ".venv", + "env", + # cache directories, etc.: ".git", ".mypy_cache", ".pytype", @@ -77,23 +79,23 @@ exclude = [ # Only enable rules that have safe autofixes; # only enable rules that are relevant to stubs select = [ + "F401", # Remove unused imports "FA", # flake8-future-annotations - "F401", # Remove unused imports - "UP004", # Remove explicit `object` inheritance - "UP006", # PEP-585 autofixes - "UP007", # PEP-604 autofixes - "UP013", # Class-based syntax for TypedDicts - "UP014", # Class-based syntax for NamedTuples - "UP019", # Use str over typing.Text - "UP035", # import from typing, not typing_extensions, wherever possible - "UP039", # don't use parens after a class definition with no bases - "PYI009", # use `...`, not `pass`, in empty class bodies - "PYI010", # function bodies must be empty - "PYI012", # class bodies must not contain `pass` - "PYI013", # non-empty class bodies must not contain `...` - "PYI020", # quoted annotations are always unnecessary in stubs - "PYI025", # always alias `collections.abc.Set` as `AbstractSet` when importing it - "PYI032", # use `object`, not `Any`, as the second parameter to `__eq__` + "PYI009", # use `...`, not `pass`, in empty class bodies + "PYI010", # function bodies must be empty + "PYI012", # class bodies must not contain `pass` + "PYI013", # non-empty class bodies must not contain `...` + "PYI020", # quoted annotations are always unnecessary in stubs + "PYI025", # always alias `collections.abc.Set` as `AbstractSet` when importing it + "PYI032", # use `object`, not `Any`, as the second parameter to `__eq__` + "UP004", # Remove explicit `object` inheritance + "UP006", # PEP-585 autofixes + "UP007", # PEP-604 autofixes + "UP013", # Class-based syntax for TypedDicts + "UP014", # Class-based syntax for NamedTuples + "UP019", # Use str over typing.Text + "UP035", # import from typing, not typing_extensions, wherever possible + "UP039", # don't use parens after a class definition with no bases ] [tool.typeshed] diff --git a/requirements-tests.txt b/requirements-tests.txt index 11fbaca82bb3..f89ad0398766 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.5.1 pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml pytype==2023.10.5; platform_system != "Windows" and python_version < "3.11" -ruff==0.0.292 # must match .pre-commit-config.yaml +ruff==0.0.292 # 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 From 00dd66967d61f29606a00d9db8b045bc55a9c63c Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 18 Oct 2023 16:51:38 -0400 Subject: [PATCH 3/3] Version merge with main --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1157ec0a9726..75603ab30b51 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,7 +52,7 @@ jobs: - uses: actions/checkout@v4 - uses: chartboost/ruff-action@v1 with: - version: "0.0.292" # must match .pre-commit-config.yaml and requirements-test.txt + version: "0.1.0" # must match .pre-commit-config.yaml and requirements-test.txt flake8: name: Lint with Flake8