Skip to content

pre-commit hook fails when using required-version #2493

Closed
@spookylukey

Description

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:

Oh no! 💥 💔 💥 The required version `21.8b0` does not match the running version `0.1.dev1+ga8b4665`!

To Reproduce

First, a temporary folder/venv to test things in:

mkdir black-pre-commit-test
cd black-pre-commit-test
`which python3.9` -m venv venv
source venv/bin/activate

Then this script:

git init
pip install pre-commit
pre-commit install


cat > .pre-commit-config.yaml << EOF
repos:
  - repo: https://github.com/psf/black
    rev: 21.8b0
    hooks:
      - id: black
        language_version: python3
EOF

cat > pyproject.toml << EOF
[tool.black]
required-version = '21.8b0'
EOF

git add .pre-commit-config.yaml

touch test.py
pre-commit run black --files test.py

Expected output

black....................................................................Passed

Actual output

black....................................................................Failed
- hook id: black
- exit code: 1

Oh no! 💥 💔 💥 The required version `21.8b0` does not match the running version `0.1.dev1+ga8b4665`!

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:

git commit .pre-commit-config.yaml -m "pre-commit"
git add test.py
git commit test.py -m "test"

Environment:

  • Version: 21.8b0
  • OS: Linux,
  • Python: 3.9.5 (i.e. which python3.9 used in the beginning of the instructions above)
  • However, the version installed by pre-commit in ~/.cache/pre-commit/repo8_9vcuko/py_env-python3/bin/python3 is different - it is whatever is pointed to by which python3, which was Python 3.8.10 first time I ran it. By changing language_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:

~/.cache/pre-commit/repo8_9vcuko/py_env-python3.9/bin/black --version

However, I haven't been able to further debug because I don't know how this line works:

from _black_version import version as __version__
- it appears to be doing some magical import.

Metadata

Assignees

No one assigned

    Labels

    C: configurationCLI and configurationC: integrationsEditor plugins and other integrationsT: documentationImprovements to the docs (e.g. new topic, correction, etc)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions