Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ruff for from __future__ import annotations checks #10910

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/check_consistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down