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

pip-compile syncing changes to pre-commit config file #1437

Open
MRigal opened this issue Jun 24, 2021 · 4 comments
Open

pip-compile syncing changes to pre-commit config file #1437

MRigal opened this issue Jun 24, 2021 · 4 comments
Labels
feature Request for a new feature pre-commit Related to pre-commit hook

Comments

@MRigal
Copy link
Member

MRigal commented Jun 24, 2021

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

  1. pip-compile would check if it finds some pre-commit config file, a path might be passed as extra args if preferred.
  2. It would extract the libraries used in pre-commit and their version
  3. 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...

@MRigal MRigal added feature Request for a new feature pre-commit Related to pre-commit hook labels Jun 24, 2021
@MRigal
Copy link
Member Author

MRigal commented Jul 14, 2021

@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...

@anrie
Copy link

anrie commented Jul 14, 2021

@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.

@asottile
Copy link
Contributor

it's not that simple, notably yaml is currently not possible to machine-rewrite: pre-commit/pre-commit#945 (comment)

@Stephen-RA-King
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request for a new feature pre-commit Related to pre-commit hook
Projects
None yet
Development

No branches or pull requests

4 participants