def generate_reports(self): """close the whole package /module, it's time to make reports ! if persistent run, pickle results for later comparison """ # Display whatever messages are left on the reporter. self.reporter.display_messages(report_nodes.Section()) if self.file_state.base_name is not None: # load previous results if any previous_stats = config.load_results(self.file_state.base_name) self.reporter.on_close(self.stats, previous_stats) if self.config.reports: sect = self.make_reports(self.stats, previous_stats) else: sect = report_nodes.Section() if self.config.reports: self.reporter.display_reports(sect) score_value = self._report_evaluation() # save results if persistent run if self.config.persistent: config.save_results(self.stats, self.file_state.base_name) else: self.reporter.on_close(self.stats, {}) score_value = None return score_value
def process_file(filename): """ Analyze the file with pylint and write the result to a database """ linter = PyLinter() checkers.initialize(linter) linter.read_config_file() linter.quiet = 1 filemods = linter.expand_files((filename, )) if filemods: old_stats = config.load_results(filemods[0].get('basename')) old_score = old_stats.get('global_note', 0.0) linter.check(filename) score = eval(linter.config.evaluation, {}, linter.stats) # Calculate the credit for both scores if score < 0: credit = 2.0 * score elif score < old_score: credit = -1.5 * (old_score - score) elif score < MINIMUM_SCORE: credit = -1.5 * (MINIMUM_SCORE - score) else: credit = score - old_score return score, old_score, credit
def _report_evaluation(self): """make the global evaluation report""" # check with at least check 1 statements (usually 0 when there is a # syntax error preventing pylint from further processing) note = None previous_stats = config.load_results(self.file_state.base_name) if self.stats["statement"] == 0: return note # get a global note for the code evaluation = self.config.evaluation try: note = eval(evaluation, {}, self.stats) # pylint: disable=eval-used except Exception as ex: # pylint: disable=broad-except msg = "An exception occurred while rating: %s" % ex else: self.stats["global_note"] = note msg = "Your code has been rated at %.2f/10" % note pnote = previous_stats.get("global_note") if pnote is not None: msg += " (previous run: %.2f/10, %+.2f)" % (pnote, note - pnote) if self.config.score: sect = report_nodes.EvaluationSection(msg) self.reporter.display_reports(sect) return note
def close(self): """close the whole package /module, it's time to make reports ! if persistent run, pickle results for later comparison """ if self.file_state.base_name is not None: # load previous results if any previous_stats = config.load_results(self.file_state.base_name) # XXX code below needs refactoring to be more reporter agnostic self.reporter.on_close(self.stats, previous_stats) if self.config.reports: sect = self.make_reports(self.stats, previous_stats) if self.config.files_output: filename = 'pylint_global.' + self.reporter.extension self.reporter.set_output(open(filename, 'w')) else: sect = Section() if self.config.reports or self.config.output_format == 'html': self.reporter.display_results(sect) # save results if persistent run if self.config.persistent: config.save_results(self.stats, self.file_state.base_name) else: if self.config.output_format == 'html': # No output will be emitted for the html # reporter if the file doesn't exist, so emit # the results here. self.reporter.display_results(Section()) self.reporter.on_close(self.stats, {})
def get_evaluation(linter): #TODO add to linter self = linter from pylint import config previous_stats = config.load_results(self.file_state.base_name) if self.stats['statement'] == 0: return evaluation = self.config.evaluation try: note = eval(evaluation, {}, self.stats) # pylint: disable=eval-used except Exception as ex: # pylint: disable=broad-except note = 'NA' pnote = previous_stats.get('global_note', None) if not pnote: if previous_stats.get('statement', 0) == 0: pnote = 'NA' else: try: pnote = eval(evaluation, {}, previous_stats) except Exception as ex: pnote = 'NA' if isinstance(note, (int, float)) and isinstance(pnote, (int, float)): dnote = note - pnote else: dnote = 'NA' results = list( zip(['stats', 'previous_stats', 'difference'], (note, pnote, dnote))) return {"evaluation": results}
def close(self): """close the whole package /module, it's time to make reports ! if persistent run, pickle results for later comparison """ if self.base_name is not None: # load old results if any old_stats = config.load_results(self.base_name) if self.config.reports: self.make_reports(self.stats, old_stats) # save results if persistent run if self.config.persistent: config.save_results(self.stats, self.base_name)
def close(self): """close the whole package /module, it's time to make reports ! if persistent run, pickle results for later comparison """ if self.base_name is not None: # load previous results if any previous_stats = config.load_results(self.base_name) # XXX code below needs refactoring to be more reporter agnostic self.reporter.on_close(self.stats, previous_stats) if self.config.reports: sect = self.make_reports(self.stats, previous_stats) if self.config.files_output: filename = 'pylint_global.' + self.reporter.extension self.reporter.set_output(open(filename, 'w')) else: sect = Section() if self.config.reports or self.config.output_format == 'html': self.reporter.display_results(sect) # save results if persistent run if self.config.persistent: config.save_results(self.stats, self.base_name)