-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
pre-commit hook fails when using required-version
#2493
Comments
a workaround until this is fixed, if you need - repo: local
hooks:
- id: black
name: black
id: black
entry: black
language: python
types_or: [python, pyi]
additional_dependencies: [black==21.8b0] |
Possible solutions could be:
I think the chances of pre-commit being OK with the first one are 0%. Can't imagine the second one would be too welcome here. Is the third one acceptable? cc @ichard26 if you have any thoughts on this one |
This is to work around this issue: psf/black#2493 Without doing this the pre-commit hook for black fails as it thinks it got the wrong version.
This is to work around this issue: psf/black#2493 Without doing this the pre-commit hook for black fails as it thinks it got the wrong version.
Here's a workaround: repos:
- repo: https://github.com/psf/black
# The `refs/tags/<tag>:refs/tags/<tag>` is needed for black's required-version to work:
# https://github.com/psf/black/issues/2493#issuecomment-1081987650
rev: 'refs/tags/22.3.0:refs/tags/22.3.0'
hooks:
- id: black Because
|
See this psf/black#2966 Also simplified pre-commit config of black based on a suggestion from https://github.com/jack1142 in psf/black#2493 (comment)
See this psf/black#2966 Also simplified pre-commit config of black based on a suggestion from https://github.com/jack1142 in psf/black#2493 (comment)
See this psf/black#2966 Also simplified pre-commit config of black based on a suggestion from https://github.com/jack1142 in psf/black#2493 (comment)
Let's mention that in the docs. |
The black pre-commit hook fails when using the `required-version` option (either as command line option or in a config file). This commit uses the fix proposed in psf/black#2493 (comment).
Another way to fix this is using the new official mirror at https://github.com/psf/black-pre-commit-mirror , see #3828 |
* Update https://github.com/pre-commit/pre-commit-hooks from `v4.4.0` to `v4.5.0`. * Downgrade https://github.com/markdownlint/markdownlint from `v0.12.0` to `v0.9.0` (see comment in `.pre-commit-config.yaml`). * Change source of `black` from https://github.com/psf/black to https://github.com/psf/black-pre-commit-mirror, because this is now the official source of the `black` pre-commit hook (see psf/black#2493 (comment)).
* Update https://github.com/pre-commit/pre-commit-hooks from `v4.4.0` to `v4.5.0`. * Downgrade https://github.com/markdownlint/markdownlint from `v0.12.0` to `v0.9.0` (see comment in `.pre-commit-config.yaml`). * Change source of `black` from https://github.com/psf/black to https://github.com/psf/black-pre-commit-mirror, because this is now the official source of the `black` pre-commit hook (see psf/black#2493 (comment)).
* Update https://github.com/pre-commit/pre-commit-hooks from `v4.4.0` to `v4.5.0`. * Downgrade https://github.com/markdownlint/markdownlint from `v0.12.0` to `v0.9.0` (see comment in `.pre-commit-config.yaml`). * Change source of `black` from https://github.com/psf/black to https://github.com/psf/black-pre-commit-mirror, because this is now the official source of the `black` pre-commit hook (see psf/black#2493 (comment)).
* Update https://github.com/pre-commit/pre-commit-hooks from `v4.4.0` to `v4.5.0`. * Downgrade https://github.com/markdownlint/markdownlint from `v0.12.0` to `v0.9.0` (see comment in `.pre-commit-config.yaml`). * Change source of `black` from https://github.com/psf/black to https://github.com/psf/black-pre-commit-mirror, because this is now the official source of the `black` pre-commit hook (see psf/black#2493 (comment)).
This is attempting to use the pre-commit hook as described under version control docs along with setting --required-version in a configuration file. The pre-commit hook fails with:
To Reproduce
First, a temporary folder/venv to test things in:
Then this script:
Expected output
Actual output
The same happens if doing a normal "git commit" - it is just easier to run the hook via
pre-commit run
directly. To test with hook:Environment:
which python3.9
used in the beginning of the instructions above)~/.cache/pre-commit/repo8_9vcuko/py_env-python3/bin/python3
is different - it is whatever is pointed to bywhich python3
, which was Python 3.8.10 first time I ran it. By changinglanguage_version
in.pre-commit-config.yaml
I can get a different version, e.g. Python 3.9.5, but it made no difference.Does this bug also happen on main?
Haven't tried, because this is specific to pinning to published versions.
Notes
I can see the incorrect Black version by doing this:
However, I haven't been able to further debug because I don't know how this line works:
black/src/black/__init__.py
Line 67 in 41e6700
The text was updated successfully, but these errors were encountered: