Run Pylint for all Python files in a directory and all subdirectories

后端 未结 14 2161
眼角桃花
眼角桃花 2021-01-30 19:45

I have

find . -iname \"*.py\" -exec pylint -E {} ;\\

and

FILES=$(find . -iname \"*.py\")
pylint -E $FILES

If

相关标签:
14条回答
  • 2021-01-30 20:22

    My one cent

    find . -type f -name "*.py" | xargs pylint 
    

    How does it work?

    find finds all files ends with py and pass to xargs, xargs runs pylint command on each file.

    NOTE: You can give any argument to pylint command as well.

    EDIT:

    According to doc we can use

    1. pylint mymodule.py

    2. pylint directory/mymodule.py

    number 2 will work if directory is a python package (i.e. has an __init__.py file or it is an implicit namespace package) or if “directory” is in the python path.

    0 讨论(0)
  • 2021-01-30 20:24

    Im using the "pylint_runner" in order to run pylint on all files in the directory and the subdirectories. Python 3.7.4

    pylint_runner 0.54

    pylint 2.4.1

    https://pypi.org/project/pylint_runner/

    Here is the command to run it from the Docker container:

    docker run -i --rm --name my_container \
      -v "$PWD":"$PWD" -w "$PWD" \
        python:3.7 \
          /bin/sh -c "pip3 install -r requirements.txt; pylint_runner -v"
    

    requirements.txt - should exist in the "$PWD" directory and contain "pylint_runner" entry.

    0 讨论(0)
  • 2021-01-30 20:25

    Just pass the directory name to the pylint command. To lint all files in ./server:

    pylint server
    
    0 讨论(0)
  • 2021-01-30 20:25

    If your goal is to run pylint on all files in the current working directory and subfolders, here is one workaround. This script runs pylint on the current directory. If __init__.py does not exist, it creates it, runs pylint, then removes it.

    #! /bin/bash -
    if [[ ! -e __init__.py ]]; then
        touch __init__.py
        pylint `pwd`
        rm __init__.py
    else
        pylint `pwd`
    fi
    
    0 讨论(0)
  • 2021-01-30 20:27
    1. touch __init__.py in the current directory
    2. touch __init__.py in every subdirectory that you want pylint to look at
    3. pylint $(pwd) (or equivalently pylint /absolute/path/to/current/directory)
    0 讨论(0)
  • 2021-01-30 20:34

    To run pylint on all *.py files in a directory and its subdirectories, you can run:

    shopt -s globstar  # for Bash
    pylint ./**/*.py
    
    0 讨论(0)
提交回复
热议问题