1

I'm trying to commit my files using using this process:

git add <filename>
git commit -m "Changes made to this commit"

When I try to commit, I receive the following error:

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

Traceback (most recent call last):
  File "/Users/danieljohnson/.cache/pre-commit/repovmer0o49/py_env-python3/bin/black", line 8, in <module>
    sys.exit(patched_main())
  File "/Users/danieljohnson/.cache/pre-commit/repovmer0o49/py_env-python3/lib/python3.9/site-packages/black/__init__.py", line 6606, in patched_main
    patch_click()
  File "/Users/danieljohnson/.cache/pre-commit/repovmer0o49/py_env-python3/lib/python3.9/site-packages/black/__init__.py", line 6595, in patch_click
    from click import _unicodefun  # type: ignore
ImportError: cannot import name '_unicodefun' from 'click' (/Users/danieljohnson/.cache/pre-commit/repovmer0o49/py_env-python3/lib/python3.9/site-packages/click/__init__.py)

Originally using Click version 8.0.3, then upgraded to 22.3.0, and also tried 8.1.3, because of this thread. However, I'm still getting the same error.

Any idea why I'm unable to commit? Could it have something to do with my changes?

torek
  • 448,244
  • 59
  • 642
  • 775
Daniel Johnson
  • 193
  • 2
  • 14

1 Answers1

3

You need to update the black pre-commit hook to a newer version. At time of writing, the latest version is 22.3.0

-   repo: https://github.com/psf/black
    rev: 22.3.0
    # ...

Or, to do this automatically (for all hooks) run:

pre-commit autoupdate

Be sure to git add your .pre-commit-config.yaml after changing it.

You must make this change through the pre-commit hook configuration. Running pip install for newer versions of click or black won't necessarily affect the packages in the virtualenv used by pre-commit.

If you still have issues, consider clearing your pre-commit cache with pre-commit clean (though this shouldn't be necessary)

sytech
  • 29,298
  • 3
  • 45
  • 86
  • Is there a way to do this withough commiting .pre-commit-config.yaml? I don't want to overwrite the .pre-commit-config.yaml that is already in gitlab – Daniel Johnson Jun 21 '22 at 20:00
  • @DanielJohnson I realize this is a late reply – technically you can just stage `.pre-commit-config.yaml` without committing and then unstage it later, but that will get messy. You could do `git commit --no-verify` if really needed, but why can't you update the pre-commit config in the repo itself? – alexia Sep 20 '22 at 16:46