【问题标题】:git-pylint-commit-hook not checking all the project filesgit-pylint-commit-hook 不检查所有项目文件
【发布时间】:2019-07-21 04:43:02
【问题描述】:

我有一个 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 文件夹中的所有文件。

我该如何解决?

如果我直接使用参数*.py **/*.py 运行pylint,它会检查所有文件。

这里是我试过的,我设置了pylintrc文件来设置参数。我在项目文件夹中添加了一个 pylintrc 文件

[pre-commit-hook]
params=*.py **/*.py

但它不起作用。

如何解决问题?

【问题讨论】:

    标签: python python-2.7 pylint


    【解决方案1】:

    您的设置在我的环境中正常工作,不需要任何 .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.pygit-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)
    

    【讨论】:

      猜你喜欢
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-18
      相关资源
      最近更新 更多