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 hook config #2963

Merged
merged 7 commits into from Sep 12, 2022
Merged

Add pre-commit hook config #2963

merged 7 commits into from Sep 12, 2022

Conversation

stefmolin
Copy link
Contributor

Addresses #2950

I'm adding an initial version of a pre-commit config file for contributors to run pre-commit hooks. After testing it out, let me know if you want any changes and whether/where we should put the setup instructions for contributors in the docs.


Setup (from the top-level of the repo):

$ pip install pre-commit
$ pre-commit install

The next time you git commit the hooks will run on the staged files. If there were any changes to the versions of checks in the config file since the last commit or this is your first time using it, it will pull down the specified versions for you:

Screen Shot 2022-08-19 at 8 48 47 PM

If you don't pass all the checks, the commit doesn't happen, but you can tack on --no-verify to your git commit command to bypass the checks.

You can test the hooks on files without committing:

$ pre-commit run --file seaborn/palettes.py
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
flake8...................................................................Passed
mypy.................................................(no files to check)Skipped

Please note that for flake8 the config option for exclude does not seem to be honored like the others in setup.cfg, so I added the equivalent pattern as an exclusion in the YAML file. Here, you can see that seaborn/cm.py is ignored for the flake8 check:

$ pre-commit run --file seaborn/cm.py
check yaml...........................................(no files to check)Skipped
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing seaborn/cm.py

trim trailing whitespace.................................................Passed
flake8...............................................(no files to check)Skipped
mypy.................................................(no files to check)Skipped

Use --all-files to run on the full repo:

$ pre-commit run --all-files
output This yields some findings:
check yaml...............................................................Passed
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing doc/_templates/autosummary/base.rst
Fixing doc/_templates/autosummary/object.rst
Fixing ci/getmsfonts.sh
Fixing doc/nextgen/Makefile
Fixing seaborn/cm.py
Fixing doc/index.rst
Fixing doc/nextgen/index.rst
Fixing doc/citing.rst
Fixing seaborn/external/docscrape.py
Fixing README.md
Fixing doc/whatsnew/v0.11.1.rst
Fixing ci/deps_pinned.txt
Fixing doc/whatsnew/v0.2.0.rst
Fixing licences/NUMPYDOC_LICENSE

trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing doc/whatsnew/v0.2.0.rst
Fixing doc/_static/copybutton.js
Fixing README.md
Fixing doc/citing.rst
Fixing doc/whatsnew/v0.11.0.rst
Fixing doc/README.md
Fixing doc/index.rst
Fixing doc/whatsnew/v0.7.0.rst
Fixing doc/nextgen/index.rst

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

tests/test_utils.py:430:11: E275 missing whitespace after keyword

mypy.....................................................................Passed

Additional hooks can be found here, and the docs for pre-commit are here.

@codecov
Copy link

codecov bot commented Aug 20, 2022

Codecov Report

Merging #2963 (66b13b9) into master (0f5a013) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2963   +/-   ##
=======================================
  Coverage   98.32%   98.32%           
=======================================
  Files          69       69           
  Lines       23230    23230           
=======================================
  Hits        22842    22842           
  Misses        388      388           
Impacted Files Coverage Δ
tests/test_utils.py 98.83% <100.00%> (ø)

@mwaskom
Copy link
Owner

mwaskom commented Sep 1, 2022

Thanks @stefmolin I'll probably wait to engage with this until after the 0.12.0 release but it looks cool.

@mwaskom
Copy link
Owner

mwaskom commented Sep 11, 2022

Thanks @stefmolin for setting this up. TBH I don't love how you end up with two sources of truth on what will be enforced vs. checked, but it's limited enough in scope to be manageable.

Can you please rebase (so you pick up #3009) and then add pre-commit to the dev extras in pyproject.toml.

If you want to add a sentence in the README about needing to do pre-commit install that would make sense too, probably right after the bit about running make lint. (e.g., "Alternately, you can use pre-commit to run lint checks on any files you are committing ...")

Also it looks like there's a handful of whitespace things that get caught when running this on all files. Do you want to run that and then commit the result as part of this PR too?

@stefmolin
Copy link
Contributor Author

Thanks @stefmolin for setting this up. TBH I don't love how you end up with two sources of truth on what will be enforced vs. checked, but it's limited enough in scope to be manageable.

Do you say this because there are additional checks here compared to make lint? Or because the Makefile has testing commands in there and this doesn't?

Can you please rebase (so you pick up #3009) and then add pre-commit to the dev extras in pyproject.toml.

If you want to add a sentence in the README about needing to do pre-commit install that would make sense too, probably right after the bit about running make lint. (e.g., "Alternately, you can use pre-commit to run lint checks on any files you are committing ...")

Also it looks like there's a handful of whitespace things that get caught when running this on all files. Do you want to run that and then commit the result as part of this PR too?

All done.

@mwaskom
Copy link
Owner

mwaskom commented Sep 11, 2022

Do you say this because there are additional checks here compared to make lint? Or because the Makefile has testing commands in there and this doesn't?

Oh I just mean that within the lint/type checks, there's some duplication of how files get selected for / excluded from testing.

@stefmolin
Copy link
Contributor Author

Oh I just mean that within the lint/type checks, there's some duplication of how files get selected for / excluded from testing.

I think I understand what you are saying. The files to include/exclude can be specified for all hooks once at the top, but the hooks don't completely overlap in what they are looking at just like the flake8 config in the setup.cfg file and the mypy config in the Makefile are different.

@mwaskom mwaskom added this to the v0.12.1 milestone Sep 11, 2022
@mwaskom mwaskom merged commit 15713b3 into mwaskom:master Sep 12, 2022
@mwaskom
Copy link
Owner

mwaskom commented Sep 12, 2022

Thanks @stefmolin, may continue to tweak over time but expect this to be very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants