【问题标题】:Run pylint for every commit on the modified changes为修改后的更改的每次提交运行 pylint
【发布时间】:2020-02-03 03:05:43
【问题描述】:

我想为每个新提交运行 pylint 并在 git 中进行修改。我是初学者,对git不太了解。

以下是我的问题:

  1. 如何使用 git 和 jenkins 获取修改后的文件
  2. 如何对文件执行 pylint。

【问题讨论】:

  • 您可以使用 pre-commit-hook 在文件被提交之前对其进行 pylint。比如:git-pylint-commit-hook.readthedocs.io/en/latest
  • 你必须在 Jenkins 中配置你的项目,定义一个 webhook 并让 jenkins 运行 pylint。出于安全原因,我建议不要让 Jenkins 在您的存储库中进行更改并防止死循环。
  • @KlausD。同意安全原因。我的项目已经集成到 Jenkins。如何进一步进行。如果您可以提供示例代码的解决方案将非常有帮助
  • 如果你已经在 J​​enkins 中进行了项目,那么运行一个额外的命令应该不会有任何问题。
  • @Klaus D. 我想从 python 文件运行 pylint。我怎样才能得到那里的文件列表??

标签: python git python-2.7 github pylint


【解决方案1】:

我想从 python 文件运行pylint
我怎样才能得到那里的文件列表?

使用GitPython,您可以轻松list files in a given commit

commit.stats.files

然后您可以使用该列表的元素应用pylint

注意:要在不使用 GitPython 的情况下执行此操作,请参阅“Get a list of changed files between two commits or branches”:比较 <SHA1><SHA1>~1:您的提交和您提交的父级(第一个祖先)。

【讨论】:

  • 如果没有 GitPython,我们不能这样做吗?如果您可以在没有 GitPython 的情况下提供解决方案,这将非常有帮助
  • @Shikhar 当然,我已经相应地编辑了我的答案。
猜你喜欢
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 2012-01-01
  • 2017-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多