python - 在 Github 提交中强制执行 PEP-8'ish 格式

标签 python git github

是否有任何预制解决方案可以在 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 中更新.
它基于 PyLintPyFlake (另请参阅“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/

相关文章:

python - pyserial - 可以从线程 a 写入串行端口,阻止从线程 b 读取?

git - Jenkins 选择了错误的 git 二进制文件

git - 将单个文件从克隆的仓库推送到 fork 的仓库

github - 在工作流/Github操作之间共享工件

git - 使用 Fork 中的 Julia 包

python - 我应该在 python 中显式关闭 zeromq 套接字吗?

python - 如果在列文本字符串中找到值,如何使用字典键添加新的数据框列

python - python/scipy中的多元样条插值?

git - "git merge"中分支名称规范中的通配符

java - 在 Eclipse 中导入克隆的 git 项目会导致一些修改的文件