34

I'm trying to setup pre-commit for a Python project's repository. Upon running pre-commit install I see an output like this:

[INFO] Installing environment for https://github.com/asottile/seed-isort-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/mirrors-pylint.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...

What are these "environments" and where are they being installed to?

planetp
  • 14,248
  • 20
  • 86
  • 160

2 Answers2

47

The environments are installed into a cache:

pre-commit by default places its repository store in ~/.cache/pre-commit -- this can be configured in two ways:

  • PRE_COMMIT_HOME: if set, pre-commit will use that location instead.
  • XDG_CACHE_HOME: if set, pre-commit will use $XDG_CACHE_HOME/pre-commit following the XDG Base Directory Specification.

disclaimer: I am the author

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • What happens if we delete it, can you add a command to reset (rebuild the cached env from scratch)? – information_interchange Mar 27 '22 at 20:37
  • 1
    you're looking for [`pre-commit install-hooks`](https://pre-commit.com/#pre-commit-install-hooks) or [`pre-commit install --install-hooks`](https://pre-commit.com/#pre-commit-install) – anthony sottile Mar 27 '22 at 21:23
  • Thanks, I believe there's a bug however. I deleted `'/Users/myname_usr/.cache/pre-commit/repoabwuil1n/`, and the mypy/pre-commit integration still continues to look here, despite no mention of `repoabwuil1n` anywhere in the config. do you know how I can force it to start from scratch? – information_interchange Mar 28 '22 at 17:48
  • 4
    not sure what you expected when you delete random stuff willy nilly from a managed directory :P. `pre-commit clean` is the intended interface – anthony sottile Mar 28 '22 at 17:58
  • Thank you, this fixed it! `pre-commit clean` is idempotent, good job :) Also, for posterity: when you update a requirements3.txt, make sure to update the ` .pre-commit-config.yaml`, otherwise if you have e.g. `mypy` hooks, it will use the old env dependencies – information_interchange Mar 29 '22 at 14:05
  • 1
    pre-commit does not install from requirements files (or any file other than `.pre-commit-config.yaml` in the repository under test) so that advice isn't really relevant – anthony sottile Mar 29 '22 at 14:07
0

Take a look at this documentation section: Managing CI Caches

intel
  • 31
  • 4