是否有任何预制解决方案可以在 Git 提交 Hook 中强制执行良好的 Python 标准?
有没有办法在本地 checkout (类似于 Bazaar,可以将提交 Hook 推送给客户端)中自动化此过程?当您 checkout 一个 repo 时,它应该已经安装了提交 Hook ,无需运行进一步的工作/命令就足够了。
例如如果您的 .py 文件有一个选项卡,提交将中止并发送一个机器人来打开发人员的屁股。
最佳答案
2020 年更新:
8 年后,您将使用 GitHub Actions , 比如 github/super-linter .
我在“How to set up actions in GitHub for new user?”中展示了这种方法。
2012年原始答案
您可以在 GitHub 端添加服务(参见“GitHub - All the Hooks”和 existing third-party services)。
但是您不能“推钩”(参见“why it is not possible to git add .git/hooks/my-hook”或“Git remote/shared pre-commit hook”。
您可以对用作 Hook 的脚本进行版本控制,但每个客户端仍需要激活其预提交 Hook (使用指向该版本控制脚本的符号链接(symbolic link))。
在 blog post 中可以看到此类版本化脚本的示例(针对 Python 标准) , 通过 Lorenzo Bolla ,并在此 GitHub repo 中更新.
它基于 PyLint和 PyFlake (另请参阅“PyLint, PyChecker or PyFlakes? ”)。
OP 在评论中提到 package vvv 0.1
A convenience utility for software source code validation and linting
VVV
is a tool for easy validation and linting integration for your software project.
With a single command validate all files, no matter in which programming language, in a source tree against a policy you specify in a simple configuration file.
VVV
prevents bad stuff to be committed in your software source control or makes cleaning it up easier.
关于python - 在 Github 提交中强制执行 PEP-8'ish 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9799209/