How to fix InvalidManifestError for pre-commit with black?
Asked Answered
M

3

6

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'         │ │
│ │               ]           
Mote answered 17/11, 2023 at 16:15 Comment(1)
In Jan 2024, this breaking change in the pre-commit hooks was reverted. See github.com/psf/black/pull/4137Anvil
C
7

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

Chough answered 17/11, 2023 at 16:38 Comment(1)
@RabihKodeih that's terrible advice -- pip is always going to give you the latest (and official) version of pre-commit. brew patches pre-commit in some weird ways and pretty often breaks the distributionChough
S
3

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

Sleigh answered 5/12, 2023 at 9:29 Comment(2)
It really did. Thanks! for saving my time.Convenience
Worked for me as well!! thank you for posting this answer! i was spinning and knew my .pre-commit file was valid.Byzantium
A
1

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.

Anvil answered 29/11, 2023 at 6:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.