Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
DEV: Add codespell to pre-commit hooks#22777
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
DEV: Add codespell to pre-commit hooks#22777
Uh oh!
There was an error while loading.Please reload this page.
Conversation
files: ^.*\.(py|c|h|md|rst|yml)$ | ||
args: [ | ||
"--ignore-words", | ||
"ci/codespell-ignore-words.txt", |
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.
The list hopefully doesn't seem too excessive, but as Matplotlib has a lot of abbreviations of variables in it this is the minimum number of ignores needed to getcodespell
working when run across all of the above file types.
I like the idea! Will this enforce not having any errors? So if one introduce a new abbreviation, it must also go in the ignore list? (I guess it is rare, but just want to understand.) Seems like not automatically changing is a good idea (not sure what the interface is, but I can see problems with selecting the wrong word etc, so better that it just warns). |
matthewfeickert commentedApr 4, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@oscargus No, it is only for character sets that diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.pyindex 1f33b9d3ec..a301a257f0 100644--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -59,6 +59,7 @@ def allow_rasterization(draw): renderer.stop_rasterizing() renderer.start_rasterizing()+ algo = 1 draw_wrapper._supports_rasterization = True return draw_wrapper $pre-commit run codespell --all-filescodespell................................................................Passed but if you had a variable named diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.pyindex 1f33b9d3ec..a543035392 100644--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -59,6 +59,7 @@ def allow_rasterization(draw): renderer.stop_rasterizing() renderer.start_rasterizing()+ mapp = 1 draw_wrapper._supports_rasterization = True return draw_wrapper $pre-commit run codespell --all-filescodespell................................................................Failed- hook id: codespell- exit code: 65lib/matplotlib/artist.py:62: mapp ==> map and then you would need to add diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.pyindex 1f33b9d3ec..90956c7a4d 100644--- a/lib/matplotlib/artist.py+++ b/lib/matplotlib/artist.py@@ -59,6 +59,7 @@ def allow_rasterization(draw): renderer.stop_rasterizing() renderer.start_rasterizing()+ map_p = 1 draw_wrapper._supports_rasterization = True return draw_wrapper $pre-commit run codespell --all-filescodespell................................................................Passed |
QuLogic commentedApr 5, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Would it fix these by capitalizing them correctly instead? They appear to be comments or docstrings that can easily be fixed.
I can't find this. You should also add (if not already automatically ignored by e.g., |
All of these can be written out as a full word, so I've opened#22784 doing so. |
matthewfeickert commentedApr 5, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@QuLogic Sadly no, as
and fromcodespell-project/codespell#2026 it doesn't really seem like this is possible to have case sensitive ignores. :(
So as these aren't typos, but just abbreviations or words that
Without it $pre-commit run codespell --all-filescodespell................................................................Failed- hook id: codespell- exit code: 65lib/matplotlib/backends/backend_pdf.py:1651: Flate ==> Flat
Correct, as this is a pre-commit hook then it only runs over files that are under version control so these don't need to be worried about as you already have them ignored. 👍 Example: $echo"mapp"> example.txt$pre-commit run codespell --all-filescodespell................................................................Passed
Awesome and thank you! I didn't want to presume that things should be modified, so I didn't make any changes in this PR or open a new one to apply changes. Once PR#22784 is merged I'll rebase this one on it. 👍 |
Oh, because it's case-insensitive, okay.
The |
matthewfeickert commentedApr 5, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Ah yeah. whoops! edit: I missed this earlier, but the addition of matplotlib/.pre-commit-config.yaml Lines 4 to 12 in9905cf0
Another note: Givencodespell-project/codespell#2063 I can't add comments to the ignore file to make it clear why these words are ignored. So the commit message and this PR will have to do for the time being. edit: I've rebased this now with the changes that are needed, so that in the event that I'm not around to have rebased this after PR#22784 is merged a maintainer can rebase it for me and I don't slow down PR review. |
cec0d3e
to40a4878
CompareI'm always confused by these pre-commit hooks as I don't currently use them. Won't our CI will have to run this as well, otherwise folks who don't use pre-commit hooks will fail folks who do? But overall, I'm not clear what problem adding this is supposed to fix. No doubt just general ignorance on my part. |
Hi@jklymak. 👋 There was back and forth discussion on PR#21583 about enablingpre-commit.ci, and while@ianhi enabled CI running in the config but disabled pushing back fixes (c.f.#21583 (comment)) matplotlib/.pre-commit-config.yaml Lines 1 to 2 ina436253
it apparently never got turned on as is unknown at the moment. My take is that pre-commit.ci is well worth the "yet another service" Ryan was unsure about, as it makes it viable for me to actually maintain pre-commit setups across many GitHub organizations, and to make sure that things are actually getting run. As a pre-commit.ci heavy user I'm very happy to discuss this if you have questions. So yes, to get the full benefit you should run it in CI, but this is easy to do.
pre-commit in general? Or the addition of |
No I'm fine with pre-commit as an idea. I just am unsure about codespell. Certainly if it works on our docs and docstrings that is helpful. I was less certain about its use in code per-se. However it seems we need to get pre-commit to run properly on our CI first? |
This just requires a maintainer turning it (https://pre-commit.ci/) on. There's nothing that needs to be done on the GitHub side. |
Great - I assume it currently passes? I'll ask on gitter if we can turn it on. |
matthewfeickert commentedApr 8, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This PR passes as $pre-commit run codespell --all-filescodespell................................................................Passed but I believe (I could be wrong, as I'm used to having $pre-commit run --all-filesCheck for added large files..............................................PassedCheck docstring is first.................................................Failed- hook id: check-docstring-first- exit code: 1lib/matplotlib/dates.py:225 Multiple module docstrings (first docstring on line 1).lib/matplotlib/_constrained_layout.py:28 Multiple module docstrings (first docstring on line 1).lib/matplotlib/backend_tools.py:992 Multiple module docstrings (first docstring on line 1).Fix End of Files.........................................................Failed- hook id: end-of-file-fixer- exit code: 1- files were modified by this hookFixing plot_types/README.rstFixing doc/api/transformations.rstFixing lib/matplotlib/tests/READMEFixing doc/devel/testing.rstFixing doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rstFixing doc/devel/style_guide.rstFixing doc/users/next_whats_new/windows_arm64.rstFixing plot_types/basic/README.rstFixing doc/api/next_api_changes/deprecations/22268-OG.rstFixing doc/api/toolkits/mplot3d/faq.rstFixing .github/workflows/tests.ymlFixing doc/_static/switcher.jsonFixing doc/_static/.gitignoreFixing doc/api/next_api_changes/deprecations/22345-JK.rstFixing LICENSE/LICENSE_COURIERTENFixing doc/users/next_whats_new/inset_axes_improvements.rstFixing plot_types/arrays/README.rstFixing LICENSE/LICENSE_BAKOMAFixing doc/api/lines_api.rstFixing LICENSE/LICENSEFixing doc/api/next_api_changes/development/22205-ES.rstFixing doc/api/next_api_changes/deprecations/22134-OG.rstFixing doc/api/_enums_api.rstFixing lib/matplotlib/backends/web_backend/css/page.cssFixing plot_types/unstructured/README.rstFixing doc/api/next_api_changes/removals/21980-CC.rstFixing doc/users/next_whats_new/list_font_names.rstFixing doc/api/next_api_changes/behavior/22691-JMK.rstFixing LICENSE/LICENSE_CARLOGOFixing plot_types/stats/README.rstFixing doc/api/next_api_changes/removals/22516-OG.rstFixing doc/api/next_api_changes/behavior/22639-RA.rstFixing README.rstFixing doc/users/next_whats_new/layout_engine.rstFixing doc/api/next_api_changes/deprecations/22133-OG.rstFixing doc/missing-references.jsonFixing LICENSE/LICENSE_STIXMixed line ending........................................................PassedTrim Trailing Whitespace.................................................Failed- hook id: trailing-whitespace- exit code: 1- files were modified by this hookFixing doc/users/next_whats_new/3d_plot_roll_angle.rstFixing doc/devel/contributing.rstFixing LICENSE/LICENSE_AMSFONTSFixing doc/users/next_whats_new/modify_stairs_fill_edge_behaviour.rstFixing .github/ISSUE_TEMPLATE/documentation.ymlFixing doc/_templates/automodule.rstFixing doc/README.txtFixing doc/users/index.rstFixing .github/ISSUE_TEMPLATE/maintenance.ymlFixing doc/users/explain/fonts.rstFixing doc/api/tri_api.rstFixing CODE_OF_CONDUCT.mdFixing doc/api/next_api_changes/development/00001-ABC.rstFixing LICENSE/LICENSE_BAKOMAFixing doc/api/lines_api.rstFixing doc/users/github_stats.rstFixing doc/users/faq/index.rstFixing doc/api/next_api_changes/removals/00001-ABC.rstFixing LICENSE/LICENSE_COLORBREWERFixing doc/api/next_api_changes/behavior/00001-ABC.rstFixing src/_backend_agg.hFixing plot_types/unstructured/README.rstFixing doc/users/resources/index.rstFixing doc/api/next_api_changes/removals/21980-CC.rstFixing .github/ISSUE_TEMPLATE/bug_report.ymlFixing lib/matplotlib/backends/web_backend/css/fbm.cssFixing examples/event_handling/README.txtFixing doc/users/next_whats_new/extending_MarkerStyle.rstFixing doc/api/patches_api.rstFixing LICENSE/LICENSE_STIXflake8...................................................................Passedcodespell................................................................Passed which maybe explains@tacaswell's comment here#21583 (comment) more. As these failing hooks are across a large number of files, if it would make it easier in a follow up PR to this one (or a new PR in which this is done in advance of this getting merged) I could apply them iand then add the commit to a matplotlib/.pre-commit-config.yaml Line 22 ina436253
could get removed (#21583 (comment)). |
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.
Just blocking until we sort out how top make sure the pre-commit doesn't get out of sync with CI. So far options seem to be run precommit-ci or make reviewdog run a parallel set of checks.
The point is that we shouldn't merge PRs that fail the precommit-ci or we will have trivial follow-up PRs to correct things for pre-commit folks.
👍 Makes sense. Comments welcome on PR#22809 which should address all of this. |
Uh oh!
There was an error while loading.Please reload this page.
40a4878
to069d55a
Compare069d55a
to0db92ad
Comparefd6b162
toff631ac
CompareOK, I have turned pre-commit on for the main repo (it was already on for pytest-mpl and ipympl). I am not super stoked that it has the ability to push to the main repo, but it is not the only application with similar access. |
ff631ac
to0a7a45f
Compare
And everything on and things are looking pretty good across the board
@tacaswell I think you already know this, so forgive me if I am over explaining, but this is because it has the ability to push back fixes if desired. As discussed before, this is turned off in the matplotlib/.pre-commit-config.yaml Lines 1 to 2 ine9e62ea
and as shown inmatthewfeickert#9 it will only attempt to push back changes to a PR if it is explicitly asked for them. You mentioned that it isn't the only application that has permissions to do this, but if the dev team isn't comfortable with this then you can simply disable it the same way you turned it on and a different approach can be used. As I imagine there might be some future discussions on this I can open up a GitHub Issue for what is the desired CI system moving forward. |
Overly permissive OAuth tokens on my mind due to the recent travis/heroku issue. We do not have any private repos (which is what those attackers were going for), but you could in principle do something "interesting" if you could get your hands on a write token to the Matplotlib repo (and by "interesting" I mean "push malicious code"). However, unless it hasadmin write privileges all of the branches that are "special" ( |
matthewfeickert commentedMay 1, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Indeed, having admin privileges would be a security disaster. I would agree that the GitHub permissions listing is not super explicit about which permissions level an associated app has but I can tell you that pre-commit.ci does not have admin privileges on any of the orgs that I'm an owner of (e.g. Scikit-HEP).@henryiii and@jpivarski can check me on that/give a better explanation if I'm missing anything relevant in the details. |
fc30ea0
toe80ce45
Comparematthewfeickert commentedMay 4, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hm. PR#22964 caught additional spelling errors. A large chunk of them I'm not surprised that matplotlib/.pre-commit-config.yaml Lines 10 to 11 inf8cd2c9
but I'm not really sure why
so I would have thought it would get things like this. edit: Guess not as $codespell --version2.1.0$echo"ploted"| codespell -# No error, so passes |
I still think this is a net-positive to add. It will catch many common mistakes early on without a dev needing to comment on nitpick wording/styling updates. |
e80ce45
to0abfef0
Comparematthewfeickert commentedMay 4, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Agreed@greglucas. The Also the next release of |
0abfef0
tobea0fe2
CompareAddhttps://github.com/codespell-project/codespell as a pre-commithook that checks for common misspellings of English words in fileswith the following extensions: .py, .c, .cpp, .h, .m, .md, .rst, .yml.Ignore instances of:* 'ans', 'axises', 'curvelinear', 'hist', 'nd', 'oly', 'thisy', 'wit'* 'ba' for bound axis and bound args* 'cannotation' for centered annotation* 'coo' for COO (Coordinate list)* 'flate' for Flate compression* 'inout' for lib/matplotlib/rcsetup.py* 'ment' for alignment with formatting* 'whis' for whikser plot* 'sur' for Big Sur* 'TE' for triangle elementsand skip checking doc/users/project/credits.rst as the list of namesof contributors isn't worth adding in to the ignore file to avoidfalse positives.
bea0fe2
to20da81f
Compare@jklymak gentle ping on this if you have time this week. |
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, been teaching an intensive course. Didn't mean to keep th block on if others are ok with this. Thanks for your patience.
@jklymak Nothing to be sorry about! Thanks very much for your continued and thoughtful feedback during the life cycle of this PR. 👍 |
matthewfeickert commentedMay 6, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Whoops, looks like I didn't rebase this against $pre-commit run codespell --all-filescodespell................................................................Failed- hook id: codespell- exit code: 65lib/matplotlib/cm.py:157: exisiting ==> existinglib/matplotlib/cm.py:238: compatbility ==> compatibility I'll open up a fix for that. |
Uh oh!
There was an error while loading.Please reload this page.
PR Summary
Resolves#22740
Addhttps://github.com/codespell-project/codespell as a pre-commit hook that checks for common misspellings of English words in files with the following extensions:
.py
,.c
,.cpp
,.h
,.m
,.md
,.rst
,.yml
.Ignore instances of:
'ot' for offset transform(Resolved in PRFix 'misspelled' transform variable #22784)and skip checkingdoc/users/project/credits.rst as the list of names of contributors isn't worth adding in to the ignore file to avoid false positives.
The above is what is needed to get
on the current
HEAD
ofmain
.Here only the
codespell
options--ignore-words
and--skip
are used, and the usual addition of--write-changes
is ignored, as it seems from PR#21583 that automatic corrections were not desired.PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).