python-3.x GitHub操作:pylint失败,F0001:没有名为__init__.py的模块(致命)

yi0zb3m4  于 2023-04-08  发布在  Python
关注(0)|答案(2)|浏览(132)

下面的GitHub Pylint starter-workflow失败了,出现了很多pylint F0001错误。
下面是github-workflow的源代码:

name: Pylint

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      with:
        python-version: 3.9
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install pylint
    - name: Analysing the code with pylint
      run: |
        pylint `ls -R|grep .py$|xargs`

以下是工作流输出的错误:

Run pylint $(ls -R | grep '.py$' | xargs)
************* Module __init__.py
__init__.py:1:0: F0001: No module named __init__.py (fatal)
__init__.py:1:0: F0001: No module named __init__.py (fatal)
************* Module pet.py
pet.py:1:0: F0001: No module named pet.py (fatal)
************* Module Authorization.py
Authorization.py:1:0: F0001: No module named Authorization.py (fatal)
************* Module Http.py
Http.py:1:0: F0001: No module named Http.py (fatal)
__init__.py:1:0: F0001: No module named __init__.py (fatal)
...
Error: Process completed with exit code 17.

为什么pylint找不到这些模块?

vmdwslir

vmdwslir1#

失败原因

GitHub操作工作流在这里包含一个bug:

| run  
    pylint `ls -R|grep .py$|xargs`
解决方案

解决方案是更换:

pylint `ls -R|grep .py$|xargs`

执行人:

pylint $(find . -name "*.py" | xargs)

bug说明

ls -R返回当前目录下的文件,格式如下:

./dir1:
__init__.py file1.py

./dir1/dir2
__init__.py file2.py

如果使用grep .py$过滤ls -R的输出,将丢失*.py文件的路径。pylint无法找到这些文件。
结果,pylint失败,出现F0001错误:

$ pylint --help-msg=F0001
:fatal (F0001):
  Used when an error occurred preventing the analysis of a module (unable to
  find it for instance). This message belongs to the master checker.
l7mqbcuq

l7mqbcuq2#

只需在终端中写入您的名称文件,而不是路径,就像这样:(我的文件是Omar.py)
$ pylintOmar.py

相关问题