def run(self, file_list): """ Runs pylint on the list of files and return a dictionary: {<filename>: [list of pylint errors], 'total': <int> - Total number of pylint messages, 'errors': <int> - Number of pylint errors, 'scores': (<filename>, score) - Individual score for each file.} :param file_list: :return: """ data = {'total': 0, 'errors': 0, 'scores': []} for filename in file_list: path, fname = os.path.split(filename) if os.path.splitext(filename)[1] != '.py': #Don't run on non-python files. continue with cd_ctx(path): short_data = pylint_raw([fname, "--reports=n", "-f", "text"]) full_data = pylint_raw([fname, "--reports=y", "-f", "text"]) score_regex = re.search( r"Your code has been rated at (-?\d+\.\d+)", full_data) if score_regex: score = score_regex.groups()[0] data['scores'].append((filename, float(score))) pylint_data = short_data.splitlines() #Remove the module line that is at the top of each pylint if len(pylint_data) > 0: pylint_data.pop(0) data[filename] = pylint_data for line in pylint_data[:]: if line.startswith('E'): data['errors'] += 1 #Ignore pylint fatal errors (problem w/ pylint, not the code generally). if line.startswith('F'): data[filename].remove(line) data['total'] += len(data[filename]) if len(data['scores']) > 0: data['average'] = (sum([score[1] for score in data['scores']]) / len(data['scores'])) else: data[ 'average'] = 9 # Default average? Comes up when all files are new. print("Total: %s" % data['total']) print("Errors: %s" % data['errors']) print("Average score: %f" % data['average']) return data
def run(self, file_list): """ Runs pylint on the list of files and return a dictionary: {<filename>: [list of pylint errors], 'total': <int> - Total number of pylint messages, 'errors': <int> - Number of pylint errors, 'scores': (<filename>, score) - Individual score for each file.} :param file_list: :return: """ data = {'total': 0, 'errors': 0, 'scores': []} for filename in file_list: path, fname = os.path.split(filename) if os.path.splitext(filename)[1] != '.py': #Don't run on non-python files. continue with cd_ctx(path): short_data = pylint_raw([fname, "--reports=n", "-f", "text"]) full_data = pylint_raw([fname, "--reports=y", "-f", "text"]) score_regex = re.search(r"Your code has been rated at (-?\d+\.\d+)", full_data) if score_regex: score = score_regex.groups()[0] data['scores'].append((filename, float(score))) pylint_data = short_data.splitlines() #Remove the module line that is at the top of each pylint if len(pylint_data) > 0: pylint_data.pop(0) data[filename] = pylint_data for line in pylint_data[:]: if line.startswith('E'): data['errors'] += 1 #Ignore pylint fatal errors (problem w/ pylint, not the code generally). if line.startswith('F'): data[filename].remove(line) data['total'] += len(data[filename]) if len(data['scores']) > 0: data['average'] = (sum([score[1] for score in data['scores']]) / len(data['scores'])) else: data['average'] = 9 # Default average? Comes up when all files are new. print("Total: %s" % data['total']) print("Errors: %s" % data['errors']) print("Average score: %f" % data['average']) return data
action="store", default=os.path.curdir) parser.add_argument("-u", "--user", help="Specify ssh user. Defaults to $USER.", action="store", default=os.environ.get('USER')) parser.add_argument( "--host", help="Manually specify the Gerrit hostname. Defaults to $GERRIT_HOST", default=os.environ.get('GERRIT_HOST')) args = parser.parse_args() if args.review_id is None: # Get the review ID from the env vars. review = os.environ.get('GERRIT_REFSPEC') else: # Manual specification of review ID. review = args.review_id review = "refs/changes/{}".format(review.lstrip('/')) print("Checking review id: {}".format(review)) repository = Repo(args.repo) with cd_ctx(args.repo): main(review_id=review, repository=repository, branch=args.branch, user=args.user, gerrit=args.host)
parser.add_argument("-b", "--branch", help="Specify a branch to compare against.", action="store", default=os.environ.get('GERRIT_BRANCH', 'development')) parser.add_argument("-r", "--repo", help="Specify location of the git repository. Defaults to current directory.", action="store", default=os.path.curdir) parser.add_argument("-u", "--user", help="Specify ssh user. Defaults to $USER.", action="store", default=os.environ.get('USER')) parser.add_argument("--host", help="Manually specify the Gerrit hostname. Defaults to $GERRIT_HOST", default=os.environ.get('GERRIT_HOST')) args = parser.parse_args() if args.review_id is None: # Get the review ID from the env vars. review = os.environ.get('GERRIT_REFSPEC') else: # Manual specification of review ID. review = args.review_id review = "refs/changes/{}".format(review.lstrip('/')) print("Checking review id: {}".format(review)) repository = Repo(args.repo) with cd_ctx(args.repo): main(review_id=review, repository=repository, branch=args.branch, user=args.user, gerrit=args.host)