Where does pre-commit install "environments"?
Asked Answered
P

1

41

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?

Pout answered 23/6, 2020 at 16:18 Comment(3)
note that your output must've come from pre-commit install --install-hooks or pre-commit install-hooks or pre-commit run, as pre-commit install by itself does not install environmentsApophyllite
I did run just pre-commit install to get that output, as I can see it in my Bash history.Pout
trust me, that's not possible -- I'm the authorApophyllite
A
61

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

Apophyllite answered 23/6, 2020 at 16:32 Comment(6)
What happens if we delete it, can you add a command to reset (rebuild the cached env from scratch)?Lupita
you're looking for pre-commit install-hooks or pre-commit install --install-hooksApophyllite
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?Lupita
not sure what you expected when you delete random stuff willy nilly from a managed directory :P. pre-commit clean is the intended interfaceApophyllite
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 dependenciesLupita
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 relevantApophyllite

© 2022 - 2024 — McMap. All rights reserved.