pip-tools
pip-tools copied to clipboard
pip-compile syncing changes to pre-commit config file
What's the problem this feature will solve?
One might have a dev_requirements file specifying linter for CI jobs that are also used by pre-commit hooks. It would be great if pip-compile could not only create/update the requirements.tx file, but also the .pre-commit-config.yaml file to not have a mismatch on black
for example.
Describe the solution you'd like
-
pip-compile
would check if it finds some pre-commit config file, a path might be passed as extra args if preferred. - It would extract the libraries used in pre-commit and their version
- It would check for the libraries to be found in the requirements.txt or setup.py and it will make sure that the version outcome is reflected in the pre-commit config file
For example, if the pre-commit config file has the following content:
repos:
- repo: https://github.com/psf/black
rev: 21.4b0
hooks:
- id: black
And dev_requirements.in the following:
black
Then we would have dev_requirements.txt with
black==21.6b0
And in .pre-commit-config.yaml
rev: 21.6b0
I'm not sure if this should be a plugin, but as pre-commit is so much used in pip-tools itself and is turning a de facto standard I think it could make sense to have directly integrated to pip-compile.
Should it be enabled by default? I would say yes, but it could be an option to be enabled, possibly by passing the config file path as argument.
Another possibility would be a pre-commit plugin, but I tend to think it should be added to pip-compile directly...
@asottile maybe you have an opinion on this? If you think it is a nice addition and give me in indication how to add/integrate this ideally, I could try to work on this somewhen this summer...
@MRigal @asottile From a quick glance I wonder if pre-commit
's autoupdate feature could be a good starting point?
The idea would be to add a --from-requirements-file
option which tries to install the version pinned by pip-tools
.
it's not that simple, notably yaml is currently not possible to machine-rewrite: https://github.com/pre-commit/pre-commit/issues/945#issuecomment-835889691
This would be a really nice feature to have. So much so that I wrote my own pre-commit plugin piptools-sync. Meant to be a stop-gap before a more formal solution was found.