python - git-pylint-commit-hook 不检查所有项目文件
问题描述
我有一个 python 2.7 项目,它有一个主文件main.py和一个src文件夹,其中包含 main.py 中使用的其他 python 文件:
project folder
|
+ main.py
|
+-src(folder)
+-file1.py
|
+....
现在,我想使用 git-pylint-commit-hook 来在我的所有 python 文件上运行 lint。我使用pip install git-pylint-commit-hook
. 我添加了一个包含
#!/usr/bin/env bash
git-pylint-commit-hook
在 /project/root/.git/hooks/pre-commit 文件夹中并使其可运行。
问题是当我提交更改时, git-pylint-commit-hook 只检查 main.py 而不会检查 src 文件夹中的所有文件。
我该如何解决?
如果我pylint
直接使用参数运行,*.py **/*.py
它会检查所有文件。
这是我尝试过的,我设置了pylintrc文件来设置参数。我在项目文件夹中添加了一个 pylintrc 文件
[pre-commit-hook]
params=*.py **/*.py
但它不起作用。
如何解决问题?
解决方案
您的设置在我的环境中正常工作,不需要任何.pylintrc文件或指定任何特殊的 pylint 配置。我认为钩子只是检查main.py 因为只有main.py包含在git add
. 确保您暂存了整个src文件夹并且它没有被 git 忽略,以便它将包含在git commit
.
$ tree -a -L 2
.
├── .git
│ ├── HEAD
│ ├── ...
│ └── refs
├── main.py
└── src
├── file1.py
└── file2.py
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: main.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
src/
在这里,git status
报告只有main.py被暂存,并且src(以及它下面的所有内容)尚未跟踪,这意味着在执行时不会包含它git commit
:
$ git commit -m "test"
Running pylint on main.py (file 1/1).. 3.3/10.00 FAILED
************* Module main
C: 1, 0: Missing module docstring (missing-docstring)
...
------------------------------------------------------------------
Your code has been rated at 3.33/10 (previous run: 3.33/10, +0.00)
正如预期的那样,只有main.py被提交,并且只有main.py被git-pylint-commit-hook
. 一旦我git add
进入src文件夹,它将包含在下一次提交尝试中。
$ git add src
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: main.py
new file: src/file1.py
new file: src/file2.py
$ git commit -m "test"
Running pylint on main.py (file 1/3).. 3.3/10.00 FAILED
...
Running pylint on src/file1.py (file 2/3).. 3.3/10.00 FAILED
...
Running pylint on src/file2.py (file 3/3).. 3.3/10.00 FAILED
...
------------------------------------------------------------------
Your code has been rated at 3.33/10 (previous run: 3.33/10, +0.00)
推荐阅读
- amazon-web-services - 如何在不更改分发的 404 页面的情况下将 (SPA) 子站点作为行为添加到现有 Cloudfront 分发中?
- matlab - 如何从 n 个大小的块中制作块稀疏矩阵?
- javascript - 如果消息不为空,useEffect 显示小吃栏,以及如何使用 useState 呢?
- python-3.x - 美丽的汤爬行者在工作中间停下来
- google-apps-script - 如何通过工作表 API 运行宏?
- linux - 批量重命名 URL 编码的文件名和文件夹路径
- git - 如何使用 GitHub API 进行快进合并?
- metadata - 如何使用 XMP 将 Dublin Core XML 文件嵌入 TIFF?
- python - pdblp con.bdh() 函数拉动产量而不是价格
- javascript - 在 effet 之前等待来自未知子组件编号的值