Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pylint

I have

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

and

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

If I understand correctly, the first command will run pylint for each of the Python files, the second one will run pylint once for all files. I expected that both commands would return the same output, but they return different results. I think this diff is somehow related to imports and F (failure) pylint messages, which occurs when a import fails and is not output by pylint -E.

Has someone already experienced this and could explain why the diff happens and what is the best way to run pylint?

like image 766
Alan Evangelista Avatar asked Apr 26 '16 18:04

Alan Evangelista


People also ask

Is Pylint recursive?

A simple pylint application that scans the current directory and any sub-directories recursively, then runs pylint on all discovered .


Video Answer


2 Answers

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

pylint ./server 

Note that this requires the __init__.py file to exist in the target directory.

like image 131
duhaime Avatar answered Oct 09 '22 06:10

duhaime


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

  3. pylint ./module

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

like image 31
sonus21 Avatar answered Oct 09 '22 06:10

sonus21