-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
DEV/STYLE: use ruff for linting #50160
Conversation
Currently, the errors that I get are:
Are that all things we are OK with to fix, or do we want to ignore those rules instead? (it seems we are currenlty not ignoring E741 (ambiguous short variable name) and E713 (Test for membership should be |
I think it'd be good to fix them - is it OK if I add a commit to do that? I'd be pretty keen to get this in and remove flake8, it'd be a nice improvement to dev workflow EDIT: timings from running on all files in CI:
3.35 seconds to lint the entire codebase...incredible 😱 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, big +1 from me (though I added a commit to fixup the remaining issues, so probably best if someone else takes a look too)
@@ -121,12 +115,6 @@ repos: | |||
rev: v0.6.7 | |||
hooks: | |||
- id: sphinx-lint | |||
- repo: https://github.com/asottile/yesqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruff
has its own version of yesqa
.pre-commit-config.yaml
Outdated
additional_dependencies: &flake8_dependencies | ||
- flake8==6.0.0 | ||
- flake8-bugbear==22.7.1 | ||
- pandas-dev-flaker==0.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely removing flake8 here means we also stop using pandas-dev-flaker. I am not familiar with it, but are there things we would like to keep from that? Is it possible to run flake8 only with the pandas-dev-flaker checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into that but it's not so simple...I think the simplest thing would be to revert the pandas-dev-flaker PR #50519
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see, that's indeed also a good option.
pyproject.toml
Outdated
] | ||
|
||
[tool.ruff.per-file-ignores] | ||
# ignoring multiline is not yet supported (https://github.com/charliermarsh/ruff/issues/1052) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be fixed now (since 0.0.203)
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
pyproject.toml
Outdated
"pandas/util/__init__.py" = ["F401"] | ||
"pandas/tests/extension/base/__init__.py" = ["F401"] | ||
# undefined name with global (https://github.com/charliermarsh/ruff/issues/960) | ||
"pandas/io/clipboard/__init__.py" = ["F821"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also be fixed since 0.0.171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, thanks! all the per-file-ignores ones could be removed in fact, the Literal one was just due to Literal
having been imported from pandas._typing
rather than typing
, so a static tool doesn't recognise it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at pandas/core/reshape/merge.py
, this may no longer be relevant, but as a heads up, we do now support a setting specifically for this use-case, to mark modules as "typing
redefinitions`.
Issue that motivated it (from Airflow): astral-sh/ruff#1744
Docs: https://github.com/charliermarsh/ruff#typing-modules
All code changes look fine to me. |
|
||
ignore = [ | ||
# space before : (needed for how black formats slicing) | ||
# "E203", # not yet implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might seem that ruff doesn't implement full of flake8, since some of those rules we ignore are not implemented, but the context is that those were not prioritized, exactly because those are not needed when using black (astral-sh/ruff#1527 (comment))
Cool - good to merge, or shall we wait for a 3rd opinion? |
+1 to move to a faster style checker. Probably comfortable merging #50519 first so we don't lose the pandas style checker checks in the meantime |
good points @twoertwein , thanks - we OK to get this in now? There's a few more checks that can be enabled (e.g. Regarding removing linters from the environment file - yeah I'd be totally in favour of that, let's just touch base on this in the call and then do it |
Just got:
Let's just spare ourselves with extra headaches and just not include it in the environment.yml file? |
conda-forge is at 0.0.215 (https://anaconda.org/conda-forge/ruff), so you can use that version |
If you want to discuss that, can you open an issue about it? (that can be done in advance of the call) |
sure, have reverted to 0.0.215 there's #46561 from sometime ago, just never got around to discussing it in calls, perhaps worth revisiting if there's time |
Let's get this in - thanks @jorisvandenbossche ! |
And thanks you for much of the follow-up work! |
# Function definition does not bind loop variable | ||
"B023", | ||
# Functions defined inside a loop must not use variables redefined in the loop | ||
# "B301", # not yet implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the drive-by, but I believe this was removed from flake8-bugbear
when it went Python 3-only: PyCQA/flake8-bugbear#182
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thanks for your input! yes there's a few things that could be addressed in a follow-up, such as this one
This is so cool! Thank you for trying Ruff. I had no idea this was happening. You all should've been bugging me way more for fixes :) (And sorry again for the PR spam. Just never thought I'd see Ruff in a project like Pandas :)) |
And thanks a lot to you for Ruff, it's a great project making the python linting experience so much better! |
https://github.com/charliermarsh/ruff/ is a faster replacement of most of the linting tools we use, and is starting to picked up by several other projects. Even project like Pandas have adopted Ruff (pandas-dev/pandas#50160) This PR replaces flake8, isort, pyupgrade.
https://github.com/charliermarsh/ruff/ is a faster replacement of most of the linting tools we use, and is starting to picked up by several other projects. Even project like Pandas have adopted Ruff (pandas-dev/pandas#50160) This PR replaces flake8, isort, pyupgrade.
https://github.com/charliermarsh/ruff/ is a faster replacement of most of the linting tools we use, and is starting to picked up by several other projects. Even project like Pandas have adopted Ruff (pandas-dev/pandas#50160) This PR replaces flake8, isort, pyupgrade.
https://github.com/charliermarsh/ruff/ is a faster replacement of most of the linting tools we use, and is starting to picked up by several other projects. Even project like Pandas have adopted Ruff (pandas-dev/pandas#50160) This PR replaces flake8, isort, pyupgrade. ``` ❯ time pre-commit run flake8 --all-files flake8...................................................................Passed pre-commit run flake8 --all-files 3.48s user 0.55s system 372% cpu 1.084 total ❯ time pre-commit run isort --all-files Run isort................................................................Passed pre-commit run isort --all-files 0.31s user 0.18s system 50% cpu 0.973 total ❯ time pre-commit run pyupgrade --all-files pyupgrade................................................................Passed pre-commit run pyupgrade --all-files 1.26s user 0.23s system 280% cpu 0.530 total ``` vs ``` ❯ time pre-commit run ruff --all-files ruff.....................................................................Passed pre-commit run ruff --all-files 0.37s user 0.16s system 142% cpu 0.373 total ``` **_Drops from 5s to 0.3s_** Some other popular tools that have adopted it: - [FastAPI](https://github.com/tiangolo/fastapi) - [Bokeh](https://github.com/bokeh/bokeh) - [Zulip](https://github.com/zulip/zulip) - [Pydantic](https://github.com/pydantic/pydantic) - [Sphinx](https://github.com/sphinx-doc/sphinx) - [Hatch](https://github.com/pypa/hatch) - [Jupyter](https://github.com/jupyter-server/jupyter_server) - [Synapse](https://github.com/matrix-org/synapse) - [Saleor](https://github.com/saleor/saleor) - [Polars](https://github.com/pola-rs/polars) - [Ibis](https://github.com/ibis-project/ibis) - [OpenBB](https://github.com/OpenBB-finance/OpenBBTerminal) It will also be used by Apache Airflow :) and should be used in Astronomer-providers too.
pandas now uses ruff for linting, see pandas-dev/pandas#50160
https://github.com/charliermarsh/ruff/ is a faster replacement of most of the linting tools we use, and is starting to picked up by several other projects. Even project like Pandas have adopted Ruff (pandas-dev/pandas#50160) This PR replaces flake8, isort, pyupgrade. ``` ❯ time pre-commit run flake8 --all-files flake8...................................................................Passed pre-commit run flake8 --all-files 3.48s user 0.55s system 372% cpu 1.084 total ❯ time pre-commit run isort --all-files Run isort................................................................Passed pre-commit run isort --all-files 0.31s user 0.18s system 50% cpu 0.973 total ❯ time pre-commit run pyupgrade --all-files pyupgrade................................................................Passed pre-commit run pyupgrade --all-files 1.26s user 0.23s system 280% cpu 0.530 total ``` vs ``` ❯ time pre-commit run ruff --all-files ruff.....................................................................Passed pre-commit run ruff --all-files 0.37s user 0.16s system 142% cpu 0.373 total ``` **_Drops from 5s to 0.3s_** Some other popular tools that have adopted it: - [FastAPI](https://github.com/tiangolo/fastapi) - [Bokeh](https://github.com/bokeh/bokeh) - [Zulip](https://github.com/zulip/zulip) - [Pydantic](https://github.com/pydantic/pydantic) - [Sphinx](https://github.com/sphinx-doc/sphinx) - [Hatch](https://github.com/pypa/hatch) - [Jupyter](https://github.com/jupyter-server/jupyter_server) - [Synapse](https://github.com/matrix-org/synapse) - [Saleor](https://github.com/saleor/saleor) - [Polars](https://github.com/pola-rs/polars) - [Ibis](https://github.com/ibis-project/ibis) - [OpenBB](https://github.com/OpenBB-finance/OpenBBTerminal) It will also be used by Apache Airflow :) and should be used in Astronomer-providers too.
flake8
is one of the slow parts of our linting (which can become especially annoying when using it as a pre-commit check), and https://github.com/charliermarsh/ruff/ is a faster replacement, and is starting to picked up by several other projects.This PR only replaces flake8 and flake8-bugbear on code (not docs) and yesqa with ruff. Later on, we could also consider replacing other parts of our linting with ruff (eg isort, pylint, pyupgrade, or some of our custom checks)