预提交与毒性 | 有什么区别| 使用范围

enk*_*oma 6 python continuous-integration pre-commit tox pre-commit.com

毒物:https: //tox.wiki/en/latest/

预提交: https://pre-commit.com/

我想了解这两种选择的界限。

我知道预提交会创建一个 py 环境 - 与 tox 相同。对我来说,他们的架构看起来有点相似。

有些人将它们结合使用...... pre-commit 不能做什么,tox 可以?我看到了一些示例,其中通过 CI 管道期间的预提交,您可以运行单元测试等。

哪一个最适合集成到 CI 构建中?

J.G*_*.G. 13

简而言之,pre-commit是一个 linter/formatter 运行器,tox是一个通用的虚拟环境管理和测试命令行工具。

虽然tox也可以运行 linter,但管理 linter 的版本很乏味。您pre-commit只需运行pre-commit autoupdate,所有的 linter 都会得到更新。

另一方面,tox可以运行许多不同 Python 版本的测试套件或覆盖率报告。这不仅对库有帮助,而且对应用程序也有帮助 - 因此您已经可以测试即将推出的 Python 版本。

tox还用于创建文档,有时也用于发布版本 - 您不能(不应该)使用pre-commit.

尽管toxGitHub 操作可以针对不同的 Python 版本进行测试,但它当然不会过时,因为您可以tox在本地和 CI 中运行。

我就这个主题做了一次闪电演讲: https://www.youtube.com/watch ?v=OnM3KuE7MQM

哪一个最适合集成到 CI 构建中?

我喜欢在 CI 中和本地运行pre-commitvia 。tox

毒性配置示例

https://github.com/jugmac00/flask-reuploaded/blob/6496f8427a06be4a9f6a5699757ca7f9aba78ef6/tox.ini#L24-L26

预提交配置示例

https://github.com/jugmac00/flask-reuploaded/blob/6496f8427a06be4a9f6a5699757ca7f9aba78ef6/.pre-commit-config.yaml