def test_format(self): from flake8.main.application import Application as Flake8 linter = Flake8() linter.run(["."]) self.assertEqual(linter.result_count, 0)
def run(self): flake8 = Flake8() flake8.initialize([]) flake8.run_checks(list(self.distribution_files())) flake8.formatter.start() flake8.report_errors() flake8.report_statistics() flake8.report_benchmarks() flake8.formatter.stop() try: flake8.exit() except SystemExit as e: # If successful, don't exit. This allows other commands to run # too. if e.code: raise
def run_flake8(args: List[str]) -> Dict[Path, List[ErrorDetail]]: output = io.StringIO() stdout = sys.stdout sys.stdout = output flake8 = Flake8() flake8.initialize(args + ['--format', FLAKE8_FORMAT]) # Only run for the checks we can do anything about: decider = flake8.guide.decider flake8.options.select = [ code for code in FIXERS.keys() if decider.decision_for(code) == Decision.Selected ] flake8.run_checks() flake8.report() sys.stdout = stdout return parse_flake8_output(output.getvalue())
def handle(self, *args, **options): os.chdir(os.path.join(os.path.join(settings.BASE_DIR, '..'))) flake8 = Flake8() flake8.run(['lana_dashboard']) flake8.exit()
elif cmd == 'lint': # Runs a linter over the code in the paths specified by LINT_PATHS. # Will check for Flake8 LINT_SETTINGS = [ '--format', '%(path)s [%(row)s:%(col)s] %(code)s: %(text)s', '--show-source' ] cmd_to_run = 'flake8' + ' '.join(LINT_DIRS) + ' '.join(LINT_SETTINGS) print_cmd(cmd_to_run) try: from flake8.main.application import Application as Flake8 except ImportError as e: print('Cannot load module: {0!r}'.format(e)) else: linter = Flake8() linter.run(LINT_DIRS + LINT_SETTINGS) elif cmd == 'clean': # Clean extraneous files like '__init__.py' files, pycache directories, migrations files generated by Django, etc. want_clean = prompt_user( 'You are about to delete migrations files. Would you like to proceed (Y/N)?' ) if not want_clean: print('Files will not be deleted. Exiting.') else: print('Deleting files...') cmd_to_run = 'find . -path "*/migrations/*.py" -not -name "__init__.py" -delete' print_cmd(cmd_to_run) os.system(cmd_to_run) cmd_to_run = 'find . -path "*/migrations/*.pyc" -delete'
if run_default: # Putting format in the setup.cfg file breaks `pip install flake8` settings = [ '--format', '%(path)s [%(row)s:%(col)s] %(code)s: %(text)s', '--show-source' ] args = LINT_PATHS + settings + args print_cmd('flake8', args) try: from flake8.main.application import Application as Flake8 except ImportError as err: print('Unable to load module: {0!r}'.format(err)) result = False else: f8 = Flake8() f8.run(args) result = f8.result_count == 0 if not result: print("The code requires some changes.") else: print("Looks good!") finally: sys.exit(int(not result)) # AutoPEP8 - auto code linter for most simple errors. if cmd in ('fix', 'autolint'): if run_default: args = LINT_PATHS + args