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

pre-commit: "Expected one of commit, commit-msg, manual, ..." since 23.11.0 #4065

Closed
martin-thoma opened this issue Nov 21, 2023 · 14 comments · Fixed by #4137
Closed

pre-commit: "Expected one of commit, commit-msg, manual, ..." since 23.11.0 #4065

martin-thoma opened this issue Nov 21, 2023 · 14 comments · Fixed by #4137
Labels
T: bug Something isn't working

Comments

@martin-thoma
Copy link

martin-thoma commented Nov 21, 2023

Describe the bug

When the pre-commit hook is installed and I commit, I get:

An error has occurred: InvalidManifestError: 
==> File /home/martin/.cache/pre-commit/repolc31_gpb/.pre-commit-hooks.yaml
==> At Hook(id='black')
==> At key: stages
==> At index 0
=====> Expected one of commit, commit-msg, manual, merge-commit, post-checkout, post-commit, post-merge, post-rewrite, prepare-commit-msg, push but got: 'pre-commit'

To Reproduce

$ python --version
3.11.1

$ python -m venv venv
$ source venv/bin/activate

$ vim .pre-commit-config.yaml
# Add this:
-   repo: https://github.com/psf/black
    rev: 23.11.0
    hooks:
    -   id: black  

$ echo "a = 'b'" > c.py

$ git init
$ git add .pre-commit-config.yaml c.py
$ pip install pre-commit
$ pre-commit install

$ pre-commit --version
pre-commit 3.5.0

$ git commit -m "Example"

The resulting error is:

An error has occurred: InvalidManifestError: 
==> File /home/martin/.cache/pre-commit/repolc31_gpb/.pre-commit-hooks.yaml
==> At Hook(id='black')
==> At key: stages
==> At index 0
=====> Expected one of commit, commit-msg, manual, merge-commit, post-checkout, post-commit, post-merge, post-rewrite, prepare-commit-msg, push but got: 'pre-commit'

Expected behavior

A pre-commit fixes c.py

Environment

  • Black's version: 23.11.0
  • OS and Python version: Linux / Python 3.11.1

Additional context

#3940

@martin-thoma martin-thoma added the T: bug Something isn't working label Nov 21, 2023
@martin-thoma
Copy link
Author

According to https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md#320---2023-03-17 the "pre-commit" value should be allowed since 3.2.0, but I think I have 3.5.0 installed.

Looking in site-packages/pre_commit/clientlib.py, I see:

HOOK_TYPES = (
    'commit-msg',
    'post-checkout',
    'post-commit',
    'post-merge',
    'post-rewrite',
    'pre-commit',
    'pre-merge-commit',
    'pre-push',
    'pre-rebase',
    'prepare-commit-msg',
)

That looks correct

@martin-thoma
Copy link
Author

The minimum_pre_commit_version should get updated to 3.2.0 at least.

@davidculley
Copy link
Contributor

Does executing pre-commit clean fix the issue?

@martin-thoma
Copy link
Author

Does executing pre-commit clean fix the issue?

Yes, it does :-) Interesting. I need to check what happens there.

Is the update of minimum_pre_commit_version required or was I wrong there?

davidculley added a commit to davidculley/black that referenced this issue Nov 21, 2023
@davidculley
Copy link
Contributor

davidculley commented Nov 21, 2023

@Wolfcast: Your error message says Expected […] commit which hints at a version of pre-commit older than version 3.2.0 — since version 3.2.0, it's pre-commit instead of just commit — and your error message continues with but got: 'pre-commit' because black 23.11.0 now requires a version of pre-commit that is newer than 3.2.0.

Try updating pre-commit:

python3 -m pip install --upgrade pre-commit

@Wolfcast
Copy link

Wolfcast commented Nov 21, 2023

@davidculley Yeah I deleted my comment before your reply :) The global pre-commit was up to date but not the one in my venv. pip install --upgrade pre-commit in the venv fixed it for me. My bad! Thanks!

@andrewmwilson
Copy link

IMO this solution is preferable #4041

The current version of Debian uses pre-commit 3.0.4, so it would be nice for it to work on that.

https://packages.debian.org/bookworm/pre-commit

@marcindulak
Copy link

Ubuntu 22.04 LTS (jammy) has pre-commit 2.17.0 https://packages.ubuntu.com/jammy/pre-commit

@davidculley
Copy link
Contributor

What am I missing @andrewmwilson @marcindulak, why can't Debian/Ubuntu users not execute pip install --user pre-commit to get a current version of pre-commit?

@marcindulak
Copy link

What am I missing @andrewmwilson @marcindulak, why can't Debian/Ubuntu users not execute pip install --user pre-commit to get a current version of pre-commit?

In hobby projects it's possible to pull packages from the internet, but in enterprises someone with required permissions would need to modify CI systems and developer machine images to include that change.

Additionally, a custom installation of pre-commit brings additional packages (see example below), and those would create a liability by extending the need of scanning them for vulnerabilities and patching, while those tasks are normally delegated to the operating system vendor

python3 -m venv venv
. venv/bin/activate
python3 -m pip install pre-commit
...
Successfully installed cfgv-3.4.0 distlib-0.3.8 filelock-3.13.1 identify-2.5.33 nodeenv-1.8.0
platformdirs-4.1.0 pre-commit-3.5.0 pyyaml-6.0.1 virtualenv-20.25.0

@Seluj78
Copy link

Seluj78 commented Dec 22, 2023

Still getting the error after a pre-commit clean and a pip install --upgrade pre-commit.

@wiseaidev
Copy link

For poetry bros, remove it first:

$ poetry remove pre-commit
Updating dependencies
Resolving dependencies... (0.5s)

Package operations: 0 installs, 0 updates, 6 removals

  • Removing cfgv (3.4.0)
  • Removing identify (2.5.33)
  • Removing nodeenv (1.8.0)
  • Removing pre-commit (2.21.0)
  • Removing pyyaml (6.0.1)
  • Removing setuptools (69.0.2)

Writing lock file

Then add it:

$ poetry add pre-commit --group dev
Using version ^3.6.0 for pre-commit

Updating dependencies
Resolving dependencies... (0.8s)

Package operations: 6 installs, 0 updates, 0 removals

  • Installing setuptools (69.0.2)
  • Installing cfgv (3.4.0)
  • Installing identify (2.5.33)
  • Installing nodeenv (1.8.0)
  • Installing pyyaml (6.0.1)
  • Installing pre-commit (3.6.0)

Writing lock file

@hauntsaninja
Copy link
Collaborator

Note for anyone currently broken by this, you can try using psf/black-pre-commit-mirror instead. This never received the change in #3940, so should still work with older versions of pre-commit. It'll also make black like 2x faster :-)

@davidculley
Copy link
Contributor

In hobby projects it's possible to pull packages from the internet, but in enterprises someone with required permissions would need to modify CI systems and developer machine images to include that change.

Additionally, a custom installation of pre-commit brings additional packages (see example below), and those would create a liability by extending the need of scanning them for vulnerabilities and patching, while those tasks are normally delegated to the operating system vendor

Thanks for the explanation @marcindulak and sorry for the late answer.

I haven't thus far found myself in such a situation, therefore I wasn't aware of the issues you describe. Now I can better put myself in your shoes, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants