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

Add pre-commit #11541

Merged
merged 52 commits into from
Apr 22, 2023
Merged

Add pre-commit #11541

merged 52 commits into from
Apr 22, 2023

Conversation

cbrnr
Copy link
Contributor

@cbrnr cbrnr commented Mar 8, 2023

This should include all style and other code quality checks. Currently, I've added Black, Ruff, and Codespell. I'll start with their default configs, but will add custom settings (probably in pyproject.toml).

To do:

  • Add custom config
  • Remove "codespell and flake" workflow as required
  • Make Pre-commit workflow required before running other workflows
  • Wait for MAINT: Use black #10641 before enabling Black
  • Add other hooks that are not available in Codespell, Ruff, and Black

@cbrnr cbrnr mentioned this pull request Mar 8, 2023
@cbrnr cbrnr linked an issue Mar 8, 2023 that may be closed by this pull request
@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

It seems like the tomli dependency lines can be removed with the next release of Codespell (codespell-project/codespell#2644).

@larsoner
Copy link
Member

larsoner commented Mar 8, 2023

New codespell released https://pypi.org/project/codespell/2.2.3/

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

That was quick, thanks for the heads up! I will remove the tomli lines.

@larsoner
Copy link
Member

larsoner commented Mar 8, 2023

... tomli is still needed for <3.11, though, assuming you want toml support

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

Yes, but I'm running pre-commit on Python 3.11.

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

Now I wonder why Codespell found these errors in the Azure job but neither in the old GitHub Action nor the new Pre-Commit one:

mne/decoding/tests/test_csp.py:263: shuold ==> should
mne/forward/forward.py:1264: matirx ==> matrix
mne/utils/check.py:850: instatiating ==> instantiating
doc/changes/0.24.inc:296: identitiy ==> identity

OK, the last one is clear, because I didn't add .inc files, but the other three?

Edit: Now the other jobs also found these misspellings, but why not previously?

@drammock
Copy link
Member

drammock commented Mar 8, 2023

Now I wonder why Codespell found these errors in the Azure job but neither in the old GitHub Action nor the new Pre-Commit one:

my suspicion would be that the azure job is somehow getting different dictionary settings or using a newer codespell version.

@drammock
Copy link
Member

drammock commented Mar 8, 2023

crossref to #11547

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

OK, I fixed it here as well.

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

But this begs the question: why do we run Codespell twice?

@drammock
Copy link
Member

drammock commented Mar 8, 2023

But this begs the question: why do we run Codespell twice?

no idea.

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 8, 2023

I'll remove it then.

@cbrnr
Copy link
Contributor Author

cbrnr commented Mar 10, 2023

For flake8 we currently have:

exclude = __init__.py,constants.py,fixes.py,resources.py,*doc/auto_*,*doc/_build*,build/*

And for pydocstyle:

match_dir = ^(?!\.|doc|tutorials|examples|logo|icons).*$
match = (?!tests/__init__\.py|fixes).*\.py

@larsoner
Copy link
Member

@cbrnr I'd like to have this sooner rather than later because the time it takes to make flake locally is starting to bug me :)

Want me to push commits to finish or can you do it in the next couple of days?

@cbrnr
Copy link
Contributor Author

cbrnr commented Apr 20, 2023

Thanks @larsoner, please feel free to finish this up. I still don't know how to run different configurations for ruff-specific tools (i.e. pydocstyle should only be run in mne/, but everything else in all directories). I also don't know how you would like to handle pydocstyle-related warnings – I'd prefer to fix them, but most warnings seem to be outside of mne/ anyway.

I'm happy to review the final PR of course!

* upstream/main: (50 commits)
  BUG: Fix bug with paths (mne-tools#11639)
  MAINT: Report download time and size (mne-tools#11635)
  MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632)
  Fix index name in to_data_frame()'s docstring (mne-tools#11457)
  MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629)
  ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554)
  make test compatible with future pandas (mne-tools#11625)
  Display SVG figures correctly in Report (mne-tools#11623)
  API: Port ieeg gui over to mne-gui-addons and add tfr gui example (mne-tools#11616)
  MAINT: Add token [ci skip] (mne-tools#11622)
  API: One cycle of backward compat (mne-tools#11621)
  MAINT: Use git rather than zipball (mne-tools#11620)
  ENH: Speed up code a bit (mne-tools#11614)
  [BUG, MRG] Don't modify info in place for transform points (mne-tools#11612)
  [BUG, MRG] Fix topomap extra plot generated, add util to check a range (mne-tools#11607)
  ENH: Add mne-bids-pipeline to mne sys_info (mne-tools#11606)
  MAINT: `coding: utf-8` is implicit in Python 3 (mne-tools#11599)
  ENH: Read eyetracking data (Eyelink) (Fork of mne-tools#10855 ) (mne-tools#11152)
  MAINT: In Python 3, do not prefix literals with `u` (mne-tools#11604)
  MAINT: object is an implicit base for all classes (mne-tools#11601)
  ...
@larsoner
Copy link
Member

Okay @cbrnr I think this is working, feel free to take a look. I think we can wait on the other points in the top comment. For the GH Actions job dependencies we should first in a separate PR put all our pytest actions in one YAML (which we only had separate for back when you couldn't restart just failed runs) along with this new precommit one. Then we can make the pytest ones depend on the style job very easily.

@larsoner larsoner marked this pull request as ready for review April 21, 2023 16:46
@larsoner larsoner requested a review from britta-wstnr as a code owner April 21, 2023 16:46
@larsoner
Copy link
Member

@drammock could you also look and make sure you're okay with these changes? Basically:

  1. Replace flake8 and pydocstyle with ruff which does the same work much faster
  2. Add .pre-commit-config where people can do pre-commit install --install-hooks and have git commit reject when style is not satisfied. Or they don't have to do this and the CIs will yell at them, as usual.
  3. Alias make flake and make pep to use the pre-commit config
  4. Update contrib docs to mention pre-commit

@larsoner
Copy link
Member

I think we can ignore the SphinxWindows failures... they don't seem related.

@larsoner larsoner added this to the 1.4 milestone Apr 21, 2023
Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

GitHub is highlighting my suggested changes in red, but AFAIK it is valid TOML to include line comments in this way. Is pyproject.toml more narrowly restricted?

.pre-commit-config.yaml Show resolved Hide resolved
doc/install/contributing.rst Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@larsoner
Copy link
Member

Locally your changes seemed to work fine so I've committed all of them, and also removed D107. It was probably made redundant at some point and we never noticed. Will merge once everything except SphinxWindows comes back green, thanks @cbrnr !

@larsoner larsoner merged commit 8325f80 into mne-tools:main Apr 22, 2023
@cbrnr
Copy link
Contributor Author

cbrnr commented Apr 22, 2023

Thank you!

@cbrnr cbrnr deleted the precommit branch April 23, 2023 13:06
larsoner added a commit to larsoner/mne-python that referenced this pull request Apr 25, 2023
* upstream/main: (152 commits)
  FIX: missing channels/fiducials can be np.nan (mne-tools#11634)
  use py3.10 in precommit config (mne-tools#11648)
  MAINT: Unify GH Actions pytest (mne-tools#11644)
  MRG: Rename "Discourse" link in top navigation to "Forum" [ci skip] (mne-tools#11649)
  ENH: Add support for Harmonic Field correction (mne-tools#11536)
  Add pre-commit (mne-tools#11541)
  BUG: Fix bug with paths (mne-tools#11639)
  MAINT: Report download time and size (mne-tools#11635)
  MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632)
  Fix index name in to_data_frame()'s docstring (mne-tools#11457)
  MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629)
  ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554)
  make test compatible with future pandas (mne-tools#11625)
  Display SVG figures correctly in Report (mne-tools#11623)
  API: Port ieeg gui over to mne-gui-addons and add tfr gui example (mne-tools#11616)
  MAINT: Add token [ci skip] (mne-tools#11622)
  API: One cycle of backward compat (mne-tools#11621)
  MAINT: Use git rather than zipball (mne-tools#11620)
  ENH: Speed up code a bit (mne-tools#11614)
  [BUG, MRG] Don't modify info in place for transform points (mne-tools#11612)
  ...
larsoner added a commit to larsoner/mne-python that referenced this pull request Apr 25, 2023
* upstream/main: (117 commits)
  FIX: missing channels/fiducials can be np.nan (mne-tools#11634)
  use py3.10 in precommit config (mne-tools#11648)
  MAINT: Unify GH Actions pytest (mne-tools#11644)
  MRG: Rename "Discourse" link in top navigation to "Forum" [ci skip] (mne-tools#11649)
  ENH: Add support for Harmonic Field correction (mne-tools#11536)
  Add pre-commit (mne-tools#11541)
  BUG: Fix bug with paths (mne-tools#11639)
  MAINT: Report download time and size (mne-tools#11635)
  MRG: Allow retrieval of channel names via make_1020_channel_selections() (mne-tools#11632)
  Fix index name in to_data_frame()'s docstring (mne-tools#11457)
  MAINT: Use VTK prerelease wheels in pre jobs (mne-tools#11629)
  ENH: Allow gradient compensated data in maxwell_filter (mne-tools#10554)
  make test compatible with future pandas (mne-tools#11625)
  Display SVG figures correctly in Report (mne-tools#11623)
  API: Port ieeg gui over to mne-gui-addons and add tfr gui example (mne-tools#11616)
  MAINT: Add token [ci skip] (mne-tools#11622)
  API: One cycle of backward compat (mne-tools#11621)
  MAINT: Use git rather than zipball (mne-tools#11620)
  ENH: Speed up code a bit (mne-tools#11614)
  [BUG, MRG] Don't modify info in place for transform points (mne-tools#11612)
  ...
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.

Replace Flake8 with Ruff?
3 participants