-
-
Save PatrickSchiffmann/94b31329fbcef92bead8 to your computer and use it in GitHub Desktop.
Module that runs pylint on all python scripts found in a directory tree..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
''' | |
Module that runs pylint on all python scripts found in a directory tree.. | |
''' | |
import re | |
import sys | |
import subprocess | |
TOTAL = 0.0 | |
COUNT = 0 | |
def check(module): | |
''' | |
apply pylint to the file specified if it is a *.py file | |
''' | |
global TOTAL, COUNT | |
if module[-3:] == ".py": | |
print "CHECKING ", module | |
pout = subprocess.Popen("pylint %s" % module, stdout=subprocess.PIPE).stdout.read() | |
for line in pout.split("\n"): | |
if re.match("E....:.", line): | |
print line | |
if "Your code has been rated at" in line: | |
print line | |
score = re.findall(r"\d.+\d\d", line)[0] | |
TOTAL += float(score) | |
COUNT += 1 | |
if __name__ == "__main__": | |
try: | |
print sys.argv | |
BASE_DIRECTORY = sys.argv[1] | |
except IndexError: | |
print "no directory specified, defaulting to current working directory" | |
BASE_DIRECTORY = os.getcwd() | |
print "looking for *.py scripts in subdirectories of ", BASE_DIRECTORY | |
for root, dirs, files in os.walk(BASE_DIRECTORY): | |
for name in files: | |
filepath = os.path.join(root, name) | |
check(filepath) | |
print "==" * 50 | |
print "%d modules found" % COUNT | |
print "AVERAGE SCORE = %.02f" % (TOTAL / COUNT) |
for me subprocess.Popen("pylint %s" % module, stdout=subprocess.PIPE).stdout.read()
fails with OSError No such file or directory
Stacktrace
python linter.py /me/my_path
['linter.py', '/me/my_path']
looking for *.py scripts in subdirectories of /me/my_path
CHECKING /me/my_path/s.py
Traceback (most recent call last):
File "linter.py", line 47, in <module>
check(filepath)
File "linter.py", line 24, in check
pout = subprocess.Popen("pylint %s" % module, stdout=subprocess.PIPE).stdout.read()
File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1025, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
system uder use
MAC OSX
Using config file /me/.pylintrc
pylint 1.8.4,
astroid 1.6.3
Python 2.7.14 (default, Mar 22 2018, 14:43:05)
Any help pointer if i'm missing something important
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BUT how to generate the report The current script is just giving the ratre..