-
-
Notifications
You must be signed in to change notification settings - Fork 612
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 for pip-compile #976
Conversation
.pre-commit-hooks.yaml
Outdated
description: Automatically compile requirements. | ||
entry: pip-compile | ||
language: python | ||
files: (requirements\.in|setup\.py)$ |
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'd suggest pyproject.toml
and setup.cfg
as well for completeness
and probably some docs on how to use this / when you might want to use this
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'd suggest
pyproject.toml
andsetup.cfg
as well for completeness
Thanks for noticing! I've missed that out. :(
and probably some docs on how to use this / when you might want to use this
Could be enough something like https://github.com/asottile/flake8-walrus#as-a-pre-commit-hook?
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.
yep! that one's a little less standard, here's the copy I usually use: https://github.com/asottile/add-trailing-comma/#as-a-pre-commit-hook
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.
May we borrow 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.
sure! you may want to suggest stages: [pre-push]
as well as pre-commit install --hook-type pre-push
as well
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.
up to you, not my project :D
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.
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've tried this hook as a user on my repositories and it looks pass_filenames: false
(and probably files
too) needs to be removed. Otherwise, pre-commit will run something like:
$ pip-compile setup.py setup.cfg
which is totally wrong, since setup.cfg is not a requirement file.
I'd let users configure files
and args
manually for their special case.
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.
if there's no good default, it might make sense to set files: ^$
+ pass_filenames: false
and document that the consumer must configure args: [requirements.in]
+ files: ^(...)$
(for example)
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.
Addressed in 5f2dea3
Add pyproject.toml and setup.cfg as well for completeness. Co-Authored-By: Anthony Sottile <asottile@umich.edu>
Add a basic doc on how to use pip-compile as pre-commit hook. Co-Authored-By: Anthony Sottile <asottile@umich.edu>
Codecov Report
@@ Coverage Diff @@
## master #976 +/- ##
==========================================
+ Coverage 99.26% 99.42% +0.16%
==========================================
Files 34 34
Lines 2446 2443 -3
Branches 306 302 -4
==========================================
+ Hits 2428 2429 +1
+ Misses 10 8 -2
+ Partials 8 6 -2
Continue to review full report at Codecov.
|
@atugushev does the hook fail for you? I tried using it but, while I successfully get a new |
I've updated the hook. Could you try it? |
I think I understand my problem a bit better now. The hook passes if |
@dirn Yeah, this works if |
- don't pass filenames since it would break CLI - update files filter
848aad8
to
14f4593
Compare
I tried in my project with the this configrepos: - repo: https://github.com/atugushev/pip-tools rev: pre-commit-hook hooks: - id: pip-compile
It worked from a It will be nice to support any requirement file in any location. |
Thank you for checking this out. Default pre-commit config handles only default values. If you have other than default values, you should configure repos:
- repo: https://github.com/atugushev/pip-tools
rev: pre-commit-hook
hooks:
- id: pip-compile
files: ^requirements/main\.(in|txt)$
args: [requirements/main.in] |
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.
🚢
Since you've had an issue with this, it seems I should definitely address this #976 (comment). |
Yes, please. Would love to see this merged😁 |
Note about configuring `args` and `files`.
Great! Please, review the latest changes if you get a chance. |
@sfdye thanks for reviewing this! 🙏 |
How that jazzband/pip-tools#976 has been merged and released, we can switch to version of the [pip-tools][pip-tools] [pre-commit][pre-commit] hook provided by [Jazzband][jazzband]. [jazzband]: https://github.com/jazzband [pip-tools]: https://pypi.org/p/pip-tools [pre-commit]: https://pre-commit.com
Resolves #974.
Refs #882.
Changelog-friendly one-liner: Add pre-commit hook for
pip-compile
.Contributor checklist
Provided the tests for the changes.