pre-commit 在哪里安装“环境”?

36

我正在尝试为Python项目的存储库设置pre-commit。运行pre-commit install后,我会看到这样的输出:

[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...

这些“环境”是什么,它们被安装在哪里?


3
请注意,您的输出必须来自于pre-commit install --install-hookspre-commit install-hookspre-commit run,因为单独运行pre-commit install不会安装环境 - anthony sottile
我只是运行了 pre-commit install 命令来获取输出,因为我可以在我的 Bash 历史记录中看到它。 - planetp
4
相信我,这是不可能的——我是作者。 - anthony sottile
2个回答

49

环境被安装到缓存中:

pre-commit默认将其仓库存储在~/.cache/pre-commit中--可以通过以下两种方式进行配置:

  • PRE_COMMIT_HOME: 如果设置了该变量,pre-commit将使用该位置。
  • XDG_CACHE_HOME: 如果设置了该变量,pre-commit将遵循XDG基础目录规范,并使用$XDG_CACHE_HOME/pre-commit

免责声明:我是作者


如果我们删除它会发生什么?你能添加一个命令来重置(从头开始重建缓存环境)吗? - information_interchange
1
你正在寻找pre-commit install-hookspre-commit install --install-hooks - anthony sottile
谢谢,我相信有一个错误。我删除了'/Users/myname_usr/.cache/pre-commit/repoabwuil1n/,但是mypy/pre-commit集成仍然在这里查找,尽管配置中没有提到repoabwuil1n。你知道我怎么能强制它从头开始吗? - information_interchange
4
当你随意从托管目录中删除随机内容时,不确定你期望得到什么结果 :P。"pre-commit clean" 是预期的接口。 - anthony sottile
谢谢,问题已解决!pre-commit clean是幂等的,做得好 :) 另外,为了记录:当你更新requirements3.txt时,请确保更新.pre-commit-config.yaml,否则如果你有例如mypy钩子,它将使用旧的环境依赖。 - information_interchange
1
pre-commit 不会从要求文件(或测试仓库中除 .pre-commit-config.yaml 以外的任何文件)安装,因此该建议并不相关。 - anthony sottile

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接