How to fix InvalidManifestError for pre-commit with black?

1.1k views Asked by At

Running python pre-commit with black latest version 23.11.0 leads to a wired InvalidManifestError.

snippet from .pre-commit-config.yaml

repos:
-   repo: https://github.com/psf/black
    rev: 23.11.0
    hooks:
    -   id: black
        types: []
        files: ^.*.pyi?$  # format .py and .pyi files`

output message:

│ │      stdout = 'An error has occurred: InvalidManifestError: \n==> File                       │ │
│ │               /Users/robot/.cache/pre-c'+329                                                 │ │
│ │ stdout_list = [                                                                              │ │
│ │               │   'An error has occurred: InvalidManifestError: \n',                         │ │
│ │               │   '==> File                                                                  │ │
│ │               /Users/robot/.cache/pre-commit/repoxhmwyits/.pre-commit-hooks.yaml\n',         │ │
│ │               │   "==> At Hook(id='black')\n",                                               │ │
│ │               │   '==> At key: stages\n',                                                    │ │
│ │               │   '==> At index 0\n',                                                        │ │
│ │               │   '=====> Expected one of commit, commit-msg, manual, merge-commit,          │ │
│ │               post-checkout, '+86,                                                           │ │
│ │               │   'Check the log at /Users/robot/.cache/pre-commit/pre-commit.log\n'         │ │
│ │               ]           
3

There are 3 answers

1
anthony sottile On BEST ANSWER

you're using an outdated version of pre-commit. you need to be using at least version 3.2.0 which introduced the renamed stages


disclaimer: I wrote pre-commit

0
jadelord On

As a workaround (because you are stuck with old pre-commit and Python versions like I am) one could use replace the repo field with

https://github.com/psf/black-pre-commit-mirror

which does not use the pre-commit stage yet.

0
Iván Sánchez On

Deleting the cache in ~/.cache/pre-commit/ worked for me