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

Is it possible to explicitly set black version in pre-commit? #122

Closed
max-sixty opened this issue Feb 20, 2022 · 4 comments · Fixed by #124
Closed

Is it possible to explicitly set black version in pre-commit? #122

max-sixty opened this issue Feb 20, 2022 · 4 comments · Fixed by #124

Comments

@max-sixty
Copy link

Quoting pydata/xarray#6290 (comment)

FYI something that's a bit surprising is that blackdoc passes in pre-commit locally but not in pre-commit.ci. My guess is that it doesn't specify the version of black it uses and so on my local machine it has an older version of black. I'm not sure whether that's possible with additional_dependencies...

Again — thank you for the excellent tool!

@keewis
Copy link
Owner

keewis commented Feb 21, 2022

this should definitely be possible, but I'm not quite sure where to put it. I would probably suggest to do that in the project's .pre-commit-config.yaml:

repos:
- repo: https://github.com/psf/black
  rev: 22.1.0
  hooks:
  - id: black

- repo: https://github.com/keewis/blackdoc
  rev: v0.3.4
  hooks:
  - id: blackdoc
    additional_dependencies: ["black==22.1.0"]
  - id: sync-black-version

where the sync-black-version hook will keep it in sync with the hook version of black. That way, I won't have to release a new version every time black does (although that might be better given that blackdoc is using some of the internal API of black).

@max-sixty
Copy link
Author

I agree it shouldn't be in the setup.cfg requirements of blackdoc (that would pin the version of black that consumers use). What do you think about putting the additional_dependencies in the blackdoc pre-commit configs? Although it would mean the black version would lag a bit (until you did the next release), it would mean that people would get a decent option by default. Having a slightly old version of black for blackdoc is fine, but having inconsistent versions between people running it isn't good.

(TBC, it's completely your call and I'm asking because I use blackdoc in lots of repos and we hopefully know each other well enough for me to ask; it's fine to say "OK but no"! :) )

@keewis
Copy link
Owner

keewis commented Feb 22, 2022

My main concern was that black would introduce changes to the code style, but I guess now that black is stable and the most important changes only land once per year this is not so important anymore. It would also avoid having the hook break because black (or tomli) changed, although that might also be avoided by increasing the test coverage...

@keewis
Copy link
Owner

keewis commented Feb 26, 2022

notes to myself:

it looks like additional_dependencies (or dependencies of hooks in general) are a unsolved issue with pre-commit: they are only updated whenever a hook is installed or updated. I can probably write a github action (or a local hook that pre-commit.ci can run) to update black whenever that is necessary, and release shortly afterwards. That might require CalVer, though...

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