-
-
Save cglukas/08de8563d24c9836689a58baf6097316 to your computer and use it in GitHub Desktop.
Python Pylint Runner to Pass (Exit 0) or Fail (Exit 1) Based on Pylint Score Threshold
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
import argparse | |
import logging | |
from pylint.lint import Run | |
logging.getLogger().setLevel(logging.INFO) | |
parser = argparse.ArgumentParser(prog="LINT") | |
parser.add_argument('-p', | |
'--path', | |
help='path to directory you want to run pylint | ' | |
'Default: %(default)s | ' | |
'Type: %(type)s ', | |
default='./src', | |
type=str) | |
parser.add_argument('-t', | |
'--threshold', | |
help='score threshold to fail pylint runner | ' | |
'Default: %(default)s | ' | |
'Type: %(type)s ', | |
default=7, | |
type=float) | |
args = parser.parse_args() | |
path = str(args.path) | |
threshold = float(args.threshold) | |
logging.info('PyLint Starting | ' | |
'Path: {} | ' | |
'Threshold: {} '.format(path, threshold)) | |
results = Run([path], exit=False) | |
final_score = results.linter.stats.global_note | |
if final_score < threshold: | |
message = ('PyLint Failed | ' | |
'Score: {} | ' | |
'Threshold: {} '.format(final_score, threshold)) | |
logging.error(message) | |
raise Exception(message) | |
else: | |
message = ('PyLint Passed | ' | |
'Score: {} | ' | |
'Threshold: {} '.format(final_score, threshold)) | |
logging.info(message) | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated lint.py for pylint version 3.0.3.
There were an outdated kwarg in
Run
and the stats are now stored as an object and not an dict.