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

Replace Flake8 checks with Ruff (except for flake8-pyi) #11496

Merged
merged 29 commits into from
Mar 10, 2024

Conversation

Avasam
Copy link
Sponsor Collaborator

@Avasam Avasam commented Feb 29, 2024

I got curious to see if we could replace the rest of Flake8 (but keeping flake8-pyi and with it flake8-noqa) with Ruff.
I've also been less selective about UP and RUF rules.

This is the result.
The bigger challenges and possible roadbump I'd say are astral-sh/ruff#3011 and plinss/flake8-noqa#22 / plinss/flake8-noqa#30

There's a couple things here that can be immediately useful that I'll split up into smaller PRs.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

stdlib/builtins.pyi Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

@Avasam
Copy link
Sponsor Collaborator Author

Avasam commented Mar 2, 2024

warning: Invalid rule code provided to # ruff: noqa at stubs/six/six/moves/builtins.pyi:1: NQA102

docs.astral.sh/ruff/settings/#lint_external

NQA is already marked as external. I opened astral-sh/ruff#10202

@Avasam
Copy link
Sponsor Collaborator Author

Avasam commented Mar 2, 2024

This will conflict with #11522 and some Ruff config changes don't make sense w/o the pre-commit changes, so we can't have this PR work standalone whilst avoiding conflicts. Keeping as draft for now for that reason.

This comment has been minimized.

This comment has been minimized.

@Avasam Avasam marked this pull request as ready for review March 3, 2024 23:25

This comment has been minimized.

pyproject.toml Show resolved Hide resolved
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! One comment suggestion, and one question:

pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

pyproject.toml Show resolved Hide resolved

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AlexWaygood
Copy link
Member

If we did want to use extend-select rather than select in pyproject.toml, we could possibly do something like this:

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index dc4bc138b..9612c5417 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -20,12 +20,12 @@ repos:
         # Run this separately because we don't really want
         # to use --unsafe-fixes for all rules
         name: Remove unnecessary `sys.version_info` blocks
-        args: ["--exit-non-zero-on-fix", "--select=UP036", "--unsafe-fixes"]
+        args: ["--isolated", "--target-version=py38", "--exit-non-zero-on-fix", "--select=UP036", "--fix", "--unsafe-fixes"]
       - id: ruff
         # Very few rules are useful to run on our test cases;
         # we explicitly enumerate them here:
         name: Run ruff on the test cases
-        args: ["--exit-non-zero-on-fix", "--select=FA,I", "--no-force-exclude", "--unsafe-fixes"]
+        args: ["--isolated", "--target-version=py38", "--exit-non-zero-on-fix", "--select=FA,I", "--no-force-exclude", "--fix", "--unsafe-fixes"]
         files: '.*test_cases/.+\.py$'

But I personally find this PR's current solution cleaner!

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 1a942aa into python:main Mar 10, 2024
63 checks passed
@Avasam Avasam deleted the go-ruff branch March 10, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants