-
Notifications
You must be signed in to change notification settings - Fork 38
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 formatter and pre-commit #2524
Conversation
holy mackerel 🐟 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2524 +/- ##
=======================================
Coverage 94.83% 94.83%
=======================================
Files 251 251
Lines 14191 14191
=======================================
Hits 13458 13458
Misses 733 733 ☔ View full report in Codecov by Sentry. |
… with wrong exceptions flagged by prospector
seems it doesn't like Python 3.10 both Linux and OSX, lemme have a look at that, bud |
Thanks! I think codespell needed an extra dependency to read the configuration file in toml format on Python 3.10. Added in fe3ff7b. |
This reverts commit 901439d.
🐈⬛ 😃 |
are we going to accept ruffly 92% coverage as the new project coverage? |
My idea was to assume that reformatting is a safe operation and does not introduce bugs.. writing tests for all the lines missing coverage seems a considerable amount of work. |
oh for sure! But I am confused as to why the coverage drops vs the original codebase, since this PR only reformats code, and doesn't introduce any hefty functionality 😕 |
It's only the diff coverage that is partial, if you click the little arrow near the bottom of the Codecov comment where it says "Additional details and impacted files" it says that overall coverage is unchanged. |
ah always found these confusing af, thanks, bud! Phew 😮💨 |
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.
really hope you didn't have to do all these changes manually, bud 🤣 Cheers muchly! We have to start thinking how we do that in ESMValTool - gonna be messy. What we doing about pull requests after we merge this - they'll be conflicting like mad I imagine
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.
last changes are ruffling no feathers 🪶
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 love it!! ❤️ This makes our code so much cleaner.
Two comments:
- Does pre-commit.ci make any changes to the code? Or does it only check the code?
- Should we consider tackling some of the Codacy issues here? Looks like most of them are very easy to fix. Just a suggestion, don't want to put extra work on you.
Thanks so much!!
full: true | ||
full: true | ||
# ignore rules that conflict with ruff formatter | ||
disable: ['E203', 'E501', 'W503'] |
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.
Is there some kind of reference that you could add as a comment here?
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.
Done in 7b0f8cd
It is possible to configure pre-commit.ci such that it will automatically fix issues and push a commit to your branch. However, I disabled it for now because I am concerned that this may cause trouble for some of our contributors if they forget to install the pre-commit hooks and then pre-commit.ci commits to their branch, they continue editing and add some more commits, try to
I would prefer not to make any more changes here because there are so many already that it is almost impossible to review. |
fully support these two from Bouwe. We may, however, need to turn on auto-pre-commit commits done by Circle (as Bouwe had it turned on for a bit until I barked at him to turn it off), for some of the older PRs that will need pre-commit be run on them, and the contributor may not be doing it or be weary/scared/not know how to do it (I reckon those aren't many, since most Core devs know their stuff). That, in the case of merge |
Perfect, this is what I wanted to hear! Will look at #2529 now to fix the tests, then we can hopefully merge this soon. |
I fixed the tests for now by pinning the pandas version to not 2.2.*. |
Peasant solution, more peasant than my peasant rounding in #2529 🐑 |
Description
Use
ruff
to format the Python code andpre-commit
to manage formatting. Enablespre-commit.ci
to check that code has been formatted correctly.These new tools replace
yapf
,isort
andflake8
(pyflakes
andpycodestyle
). I have droppeddocformatter
from the pre-commit hooks because it makes changes to docstrings that do not always look good (e.g. it will happily cut a sentence into two pieces to make the first half of the sentence fit on the first line of the docstring).Please install the pre-commit hooks by going to the directory where you have checked out ESMValCore and running
To format your code (and check for pycodestyle, pyflakes, and mypy issues) run:
This will also automatically be done (on changed files only) whenever you commit your changes.
See ESMValGroup/ESMValTool#2161
Link to documentation: https://esmvaltool--2524.org.readthedocs.build/projects/ESMValCore/en/2524/contributing.html#code-quality
Git branch upgrade instructions (once this has been merged)
To upgrade your existing git branches and open pull requests to the new formatting once this pull request has been merged into the
main
branch, the following procedure is recommended to minimize merge conflicts:Step 1: reformat changed Python files with ruff, this is needed to minimize merge conflicts in the next step
Step 2: merge the
main
branch into your branchgit pull origin main --no-ff # edit code to address merge conflicts, use `git add path/to/file.py` to mark as solved and then run: git commit -n
Step 3: start using pre-commit to format and check your code
To test these instructions before this has been merged, you can replace
main
withruff-format
(this branch) in the commands above.Before you get started
Checklist
It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.
To help with the number pull requests: