def process_module(self, node): ''' process a module the module's content is accessible via node.file_stream object ''' if node.path not in _PROCESSED_NODES: stylechecker = StyleGuide(parse_argv=False, config_file=True, quiet=2, reporter=PyLintPEP8Reporter) _PROCESSED_NODES[node.path] = stylechecker.check_files([node.path]) for code, lineno in _PROCESSED_NODES[node.path].locations: pylintcode = '{0}8{1}'.format(code[0], code[1:]) if pylintcode in self.msgs_map: # This will be handled by PyLint itself, skip it continue if pylintcode not in self.msgs: # Log warning?? continue self.add_message(pylintcode, line=lineno, args=code)
def test_pep8(self): """ Test PEP8 conformance """ style = StyleGuide(quiet=True) check = style.check_files([MODEL]) self.assertEqual(check.total_errors, 0)
def pep8(): """ Style tests with PEP8 """ from pep8 import StyleGuide code_dir = project_root().join('dockci') pep8style = StyleGuide(parse_argv=False) report = pep8style.check_files((code_dir.strpath,)) if report.total_errors: return 1
def find_issues(check_files, dirnames): """ Finds all issues in the given directories (filtered by check_files). """ checker = StyleGuide() checker.options.ignore = IGNORE_ERRORS filenames = dirnames if check_files is not None: filenames = filter_file_list(check_files, dirnames) report = checker.check_files(filenames) if len(report.messages) > 0: yield ("style issue", "python code violates pep8")
def find_issues(check_files, dirnames): """ Finds all issues in the given directories (filtered by check_files). """ checker = StyleGuide() checker.options.ignore = IGNORE_ERRORS filenames = dirnames if check_files is not None: filenames = filter_file_list(check_files, dirnames) report = checker.check_files(filenames) if len(report.messages) > 0: yield ("style issue", "python code violates pep8")
def pep8_check(pkg_name, dir_path): print("Scanning {}".format(dir_path)) sg = StyleGuide(reporter=Dict8orReport, max_line_length=120) r = sg.check_files([dir_path]) n_warn = r.get_count('W') n_err = r.get_count('E') redis.hmset('pkg:' + pkg_name, { 'details': json.dumps(r.history), 'warnings': n_warn, 'errors': n_err }) redis.zadd('ranking', n_err * 2 + n_warn, pkg_name) print("Done!")
def process_module(self, node): ''' process a module the module's content is accessible via node.file_stream object ''' if node.path not in _PROCESSED_NODES: stylechecker = StyleGuide(parse_argv=False, config_file=True, quiet=2, reporter=PyLintPEP8Reporter) _PROCESSED_NODES[node.path] = stylechecker.check_files([node.path]) for code, lineno in _PROCESSED_NODES[node.path].locations: pylintcode = '{0}8{1}'.format(code[0], code[1:]) if pylintcode in self.msgs_map: # This will be handled by PyLint itself, skip it continue if pylintcode not in _KNOWN_PEP8_IDS: if pylintcode not in _UNHANDLED_PEP8_IDS: _UNHANDLED_PEP8_IDS.append(pylintcode) msg = 'The following code, {0}, was not handled by the PEP8 plugin'.format( pylintcode) if logging.root.handlers: logging.getLogger(__name__).warning(msg) else: sys.stderr.write('{0}\n'.format(msg)) continue if pylintcode not in self._msgs: # Not for our class implementation to handle continue if code in ('E111', 'E113'): if _PROCESSED_NODES[node.path].lines[ lineno - 1].strip().startswith('#'): # If E111 is triggered in a comment I consider it, at # least, bad judgement. See https://github.com/jcrocholl/pep8/issues/300 # If E113 is triggered in comments, which I consider a bug, # skip it. See https://github.com/jcrocholl/pep8/issues/274 continue self.add_message(pylintcode, line=lineno, args=code)
def process_module(self, node): ''' process a module the module's content is accessible via node.file_stream object ''' if node.path not in _PROCESSED_NODES: stylechecker = StyleGuide( parse_argv=False, config_file=True, quiet=2, reporter=PyLintPEP8Reporter ) _PROCESSED_NODES[node.path] = stylechecker.check_files([node.path]) for code, lineno in _PROCESSED_NODES[node.path].locations: pylintcode = '{0}8{1}'.format(code[0], code[1:]) if pylintcode in self.msgs_map: # This will be handled by PyLint itself, skip it continue if pylintcode not in _KNOWN_PEP8_IDS: if pylintcode not in _UNHANDLED_PEP8_IDS: _UNHANDLED_PEP8_IDS.append(pylintcode) msg = 'The following code, {0}, was not handled by the PEP8 plugin'.format(pylintcode) if logging.root.handlers: logging.getLogger(__name__).warning(msg) else: sys.stderr.write('{0}\n'.format(msg)) continue if pylintcode not in self._msgs: # Not for our class implementation to handle continue if code in ('E111', 'E113'): if _PROCESSED_NODES[node.path].lines[lineno-1].strip().startswith('#'): # If E111 is triggered in a comment I consider it, at # least, bad judgement. See https://github.com/jcrocholl/pep8/issues/300 # If E113 is triggered in comments, which I consider a bug, # skip it. See https://github.com/jcrocholl/pep8/issues/274 continue self.add_message(pylintcode, line=lineno, args=code)
def test_pep8style(self): test_dir = os.path.dirname(os.path.abspath(__file__)) dist_dir = os.path.dirname(test_dir) pep8style = StyleGuide() saved_stdout, sys.stdout = sys.stdout, io.StringIO() try: pep8style.input_dir(dist_dir) output = sys.stdout.getvalue() finally: sys.stdout = saved_stdout report = pep8style.check_files() newline = os.linesep result_format = 'PEP8 failed (errors={:d}, warnings={:d})' + newline result = result_format.format(report.get_count('E'), report.get_count('W')) statistics = newline.join(report.get_statistics()) + newline message = newline.join((result, statistics, output)) self.assertEqual(report.get_count(), 0, message)
def process_module(self, node): """ process a module the module's content is accessible via node.file_stream object """ if node.path not in _PROCESSED_NODES: stylechecker = StyleGuide(parse_argv=False, config_file=True, quiet=2, reporter=PyLintPEP8Reporter) _PROCESSED_NODES[node.path] = stylechecker.check_files([node.path]) for code, lineno in _PROCESSED_NODES[node.path].locations: pylintcode = "{0}8{1}".format(code[0], code[1:]) if pylintcode in self.msgs_map: # This will be handled by PyLint itself, skip it continue if pylintcode not in self.msgs: # Log warning?? continue self.add_message(pylintcode, line=lineno, args=code)
def run(self): if self.pep8_output: stdout, sys.stdout = sys.stdout, self.pep8_output stderr, sys.stderr = sys.stderr, self.pep8_output config_opts = self._parse_opts() pep8style = StyleGuide(parse_argv=False, config_file=False, **config_opts) options = pep8style.options options.exclude.extend(['test', 'tests']) report = pep8style.check_files(self.check_dirs) if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if report.total_errors: if options.count: log.error("Total Errors: " + str(report.total_errors)) if self.pep8_output: sys.stdout = stdout sys.stderr = stderr self.pep8_output.close()
print("Execution time was {0} seconds.\n".format(execution_time)) # We're using RMSE as a metric. error = math.sqrt( mean_squared_error(predictions, prediction_df[settings.PREDICTION_COLUMN])) print("Found root mean squared error of: {0}\n".format(error)) # Setup a buffer to capture pep8 output. buffer = StringIO.StringIO() sys.stdout = buffer # Initialize and run a pep8 style checker. pep8style = StyleGuide(ignore="E121,E123,E126,E226,E24,E704,E501") pep8style.input_dir(settings.BASE_DIR) report = pep8style.check_files() # Change stdout back to the original version. sys.stdout = sys.__stdout__ pep8_results = buffer.getvalue() if report.total_errors > 0: print("Pep8 violations found! They are shown below.") print("----------------------") print(pep8_results) # Write all the results to a file if needed. if args.write: write_data = { "error": error, "execution_time": execution_time,
from os import getcwd from pep8 import StyleGuide pep8style = StyleGuide(quiet=True) r = pep8style.check_files([__file__]) print r.__dict__ print "total_errors",r.total_errors print "file_errors",r.file_errors print "line_offset",r.line_offset print "lines",r.lines print "filename",r.filename print "elapsed",r.elapsed print "_benchmark_keys",r._benchmark_keys print "expected",r.expected #print r._ignore_code() print "counters",r.counters #pep8style.check_files(paths=[getcwd()]) #...path to files/dirs to check...