def test_syntax(self): """ From flake8 """ packages = ["signals"] # Prepare config_file = os.path.join(os.path.dirname(__file__), "..", "setup.cfg") flake8_style = get_style_guide(config_file=config_file) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() # Save to file for later printing instead of printing now old_stdout = sys.stdout sys.stdout = out = open(".syntax_output", "w+") # Run the checkers report = flake8_style.check_files(paths=packages) sys.stdout = old_stdout # Print the final report options = flake8_style.options if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if report.total_errors: out.close() with open(".syntax_output") as f: self.fail("{0} Syntax warnings!\n\n{1}".format(report.total_errors, f.read()))
def check_syntax(self): """ From flake8 """ packages = settings.PACKAGES_TO_TEST # Prepare config_file = getattr(yak_settings, 'FLAKE8_CONFIG', flake8.main.DEFAULT_CONFIG) flake8_style = get_style_guide(config_file=config_file) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() # Save to file for later printing instead of printing now old_stdout = sys.stdout sys.stdout = out = open('syntax_output', 'w+') # Run the checkers report = flake8_style.check_files(paths=packages) sys.stdout = old_stdout # Print the final report options = flake8_style.options if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if report.total_errors: out.close() with open("syntax_output") as f: self.fail("{0} Syntax warnings!\n\n{1}".format(report.total_errors, f.read()))
def test_syntax(self): """ From flake8 """ packages = ['signals'] # Prepare config_file = os.path.join(os.path.dirname(__file__), '..', 'setup.cfg') flake8_style = get_style_guide(config_file=config_file) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() # Save to file for later printing instead of printing now old_stdout = sys.stdout sys.stdout = out = open('.syntax_output', 'w+') # Run the checkers report = flake8_style.check_files(paths=packages) sys.stdout = old_stdout # Print the final report options = flake8_style.options if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if report.total_errors: out.close() with open(".syntax_output") as f: self.fail("{0} Syntax warnings!\n\n{1}".format(report.total_errors, f.read()))
def main(): global pep8style # parse out our flags so pep8 doesn't get confused parser = get_parser() # This is required so we can parse out our added options opts, args = pep8.process_options(parse_argv=True, parser=parser) if opts.install_hook: from flake8.hooks import install_hook install_hook() if opts.builtins: s = '--builtins={0}'.format(opts.builtins) sys.argv.remove(s) if opts.exit_zero: sys.argv.remove('--exit-zero') if opts.install_hook: sys.argv.remove('--install-hook') complexity = opts.max_complexity if complexity > 0: sys.argv.remove('--max-complexity={0}'.format(complexity)) # make sure pep8 gets the information it expects sys.argv.pop(0) sys.argv.insert(0, 'pep8') read_config(opts, parser) # We then have to re-parse argv to make sure pep8 is properly initialized pep8style = pep8.StyleGuide(parse_argv=True, config_file=True) merge_opts(pep8style.options, opts) warnings = 0 stdin = None builtins = set(opts.builtins.split(',')) if builtins: orig_builtins = set(flakey.checker._MAGIC_GLOBALS) flakey.checker._MAGIC_GLOBALS = orig_builtins | builtins if pep8style.paths and pep8style.options.filename is not None: for path in _get_python_files(pep8style.paths): if path == '-': if stdin is None: stdin = read_stdin() warnings += check_code(stdin, opts.ignore, complexity) else: warnings += check_file(path, opts.ignore, complexity) else: stdin = read_stdin() warnings += check_code(stdin, opts.ignore, complexity) if opts.exit_zero: raise SystemExit(0) raise SystemExit(warnings)
def check_file(path, flake8ignore): """Run flake8 over a single file, and return the number of failures.""" flake8_style = get_style_guide(parse_argv=True) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() return flake8_style.input_file(str(path), expected=flake8ignore)
def check_file(path, flake8ignore): """Run flake8 over a single file, and return the number of failures.""" flake8_style = get_style_guide(parse_argv=False) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() return flake8_style.input_file(str(path), expected=flake8ignore)
def check_file(path, flake8ignore, maxlength): """Run flake8 over a single file, and return the number of failures.""" if maxlength: flake8_style = get_style_guide( parse_argv=False, paths=['--max-line-length', maxlength]) else: flake8_style = get_style_guide(parse_argv=False) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() return flake8_style.input_file(str(path), expected=flake8ignore)
def check_file(path, flake8ignore, maxlength): """Run flake8 over a single file, and return the number of failures.""" if maxlength: flake8_style = get_style_guide(parse_argv=False, paths=['--max-line-length', maxlength]) else: flake8_style = get_style_guide(parse_argv=False) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() return flake8_style.input_file(str(path), expected=flake8ignore)
def main(): """Parse options and run checks on Python source.""" # Prepare flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() # Run the checkers report = flake8_style.check_files() exit_code = print_report(report, flake8_style) raise SystemExit(exit_code > 0)
def main(): """Parse options and run checks on Python source.""" # Prepare flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG) options = flake8_style.options if options.install_hook: from flake8.hooks import install_hook install_hook() # Run the checkers report = flake8_style.check_files() # Print the final report options = flake8_style.options if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if report.total_errors: if options.count: sys.stderr.write(str(report.total_errors) + '\n') if not options.exit_zero: raise SystemExit(1)
# -*- coding: utf-8 -*-