melvio
melvio

Reputation: 1140

GitHub Actions: pylint fails with F0001: No module named __init__.py (fatal)

The following GitHub Pylint starter-workflow fails with lots of pylint F0001 errors.

This is the github-workflow source code:

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`

These are the errors that the workflow outputs:

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.

Why can't pylint find these modules?

Upvotes: 5

Views: 6182

Answers (2)

Omar Hussein
Omar Hussein

Reputation: 1

Just write in the terminal your file name, not the path -- like this : (my file is Omar.py)

$ pylint Omar.py

Upvotes: 0

melvio
melvio

Reputation: 1140

Cause of the failure

The GitHub action workflow contains a bug over here:

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

The solution

The solution is to replace:

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

By:

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

Explanation of the bug

ls -R returns the files in the current directory with the following format:

./dir1:
__init__.py file1.py

./dir1/dir2
__init__.py file2.py

If you filter the output of ls -R with grep .py$, you'll lose the path to the *.py files. pylint cannot find these files.

As a result, pylint fails with F0001 errors:

$ 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.

Upvotes: 6

Related Questions