def test_pep8(self): """ Test PEP8 conformance """ style = StyleGuide(quiet=True) check = style.check_files([MODEL]) self.assertEqual(check.total_errors, 0)
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_conformance(self): pep8style = StyleGuide(testsuite=True) report = pep8style.init_report() pep8style.input_dir(dirname=join(getcwd(), 'accio')) self.assertEqual(report.total_errors, 0, "Found code style errors.")
def process_items(reporter, items, tester): """Process list of modules or packages. """ test_pylint = tester in ("pylint", "all",) test_pep8 = tester in ("pep8", "all",) if test_pep8: # PEP8 report instance setup pep8style = StyleGuide(parse_argv=False, config_file=False) if reporter.name == "csv": pep8style.options.report = CsvPep8Report(pep8style.options, reporter.writer) else: colorized = (reporter.name == "colorized") pep8style.options.report = Pep8Report(pep8style.options, reporter.line_format, reporter.out, colorized) pylint_rc_path = os.path.join(_CURRENT_PATH, "pylint.rc") for item in items: path = os.path.join(_BASE_PATH, item) if test_pylint: # Pylint tests lint.Run([path, "--rcfile={0}".format(pylint_rc_path)], reporter=reporter, exit=False) if test_pep8: # Pep8 tests if item.endswith(".py"): pep8style.input_file(path) else: pep8style.input_dir(path)
def test_pep8_conformance(self): pep8style = StyleGuide(testsuite=True, exclude=["python-yahooapi"]) report = pep8style.init_report() pep8style.input_dir(dirname=join(getcwd(), 'yfantasy')) self.assertEqual(report.total_errors, 0, "Found code style errors.")
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 test_pep8_conformance(): """Test source code for PEP8 conformance.""" pep8style = StyleGuide(max_line_length=100) report = pep8style.options.report report.start() base_path = os.path.join(os.path.dirname(__file__), '..') pep8style.input_dir(os.path.join(base_path, 'ros_buildfarm')) pep8style.input_dir(os.path.join(base_path, 'scripts')) report.stop() assert report.total_errors == 0, \ 'Found %d code style errors (and warnings)' % report.total_errors
def run(path, code=None, params=None, **meta): """Check code with PEP8. :return list: List of errors. """ parser = get_parser() for option in parser.option_list: if option.dest and option.dest in params: value = params[option.dest] if not isinstance(value, str): continue params[option.dest] = option.convert_value(option, params[option.dest]) P8Style = StyleGuide(reporter=_PEP8Report, **params) buf = StringIO(code) return P8Style.input_file(path, lines=buf.readlines())
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 run(path, code=None, params=None, **meta): """Check code with PEP8. :return list: List of errors. """ parser = get_parser() for option in parser.option_list: if option.dest and option.dest in params: value = params[option.dest] if not isinstance(value, str): continue params[option.dest] = option.convert_value( option, params[option.dest]) P8Style = StyleGuide(reporter=_PEP8Report, **params) buf = StringIO(code) return P8Style.input_file(path, lines=buf.readlines())
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): from pep8 import StyleGuide self.run_command("egg_info") files = self.get_finalized_command("egg_info") report = StyleGuide().check_files( [p for p in files.filelist.files if p.endswith(".py")]) if report.total_errors: msg = "Found {} PEP8 violations".format(report.total_errors) raise DistutilsError(msg) else: log.info("No PEP8 violations found")
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()
def process_items(reporter, items, tester): """Process list of modules or packages. """ test_pylint = tester in ( "pylint", "all", ) test_pep8 = tester in ( "pep8", "all", ) if test_pep8: # PEP8 report instance setup pep8style = StyleGuide(parse_argv=False, config_file=False) if reporter.name == "csv": pep8style.options.report = CsvPep8Report(pep8style.options, reporter.writer) else: colorized = (reporter.name == "colorized") pep8style.options.report = Pep8Report(pep8style.options, reporter.line_format, reporter.out, colorized) pylint_rc_path = os.path.join(_CURRENT_PATH, "pylint.rc") for item in items: path = os.path.join(_BASE_PATH, item) if test_pylint: # Pylint tests lint.Run([path, "--rcfile={0}".format(pylint_rc_path)], reporter=reporter, exit=False) if test_pep8: # Pep8 tests if item.endswith(".py"): pep8style.input_file(path) else: pep8style.input_dir(path)
# Find how long it took to execute. execution_time = time.time() - start 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 = {
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...
def test_style(self): """tests for correct pep8 style""" style = StyleGuide(quiet=True).check_files(["models/city.py"]) self.assertEqual(style.total_errors, 0, "fix pep8")
def pep8(self): from pep8 import StyleGuide sg = StyleGuide() sg.input_dir('aragog') sg.input_dir('test')
def test_pep8(): report = StyleGuide(ignore=['E501', 'E402']).check_files( [os.path.dirname(os.path.abspath(__file__)) + '/..']) report.print_statistics() assert not report.messages