def check(path, ignore=None, to_file=False): quite = '-qq' source = '--show-source' pep = '--show-pep8' rep = '--repeat' args = [rep] if ignore is None: ignore = [] if to_file: out_file = './pep8.txt' if os.path.exists(out_file): os.remove(out_file) file_handle = open(out_file, 'a') files_count = 0 for the_file in walk_path(path, recurse=True, pattern='*.py', ignore=ignore): arglist = args[:] + [the_file] pep8.process_options(arglist) try: pep8.input_file(the_file) error_stats = pep8.get_error_statistics() warning_stats = pep8.get_warning_statistics() if to_file: if warning_stats or error_stats: file_handle.write('\n') file_handle.write(the_file) file_handle.write('\n') for warning in warning_stats: file_handle.write("%s\n" % warning) for errors in error_stats: file_handle.write("%s\n" % errors) files_count += 1 sys.stdout.write('Processed %d file(s) \r' % files_count) except Exception, e: pass
def display_pep8(self, path, summary=True): pep8_out = StringIO() try: with RedirectedIO(target=pep8_out, close_target=False): pep8.process_options([path]) pep8.input_file(path) error_stats = pep8.get_error_statistics() warning_stats = pep8.get_warning_statistics() val = pep8_out.getvalue().splitlines() for line in [ x.split(':',1)[1] for x in val if ':' in x]: self.writeln(line) if summary: self.writeln() self.writeln("Summary:") for e in error_stats: self.writeln(e) for w in warning_stats: self.writeln(w) self.writeln() except tokenize.TokenError: self.boxed_text(["PEP8 processing failed - check your source code"], symbol="#")
def check(filename): pep8.process_options(['-qq', filename]) pep8.input_file(filename) return pep8.get_error_statistics(), pep8.get_warning_statistics()