From da2182151773e5e37faa87ad607308694e6c1997 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 10 Mar 2016 19:00:07 -0600 Subject: [PATCH] Make flake8 actually work --- flake8/checker.py | 13 +++++++++++-- flake8/main/cli.py | 17 ++++++++++++++++- flake8/processor.py | 4 +++- setup.py | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/flake8/checker.py b/flake8/checker.py index c058db5..675ad0c 100644 --- a/flake8/checker.py +++ b/flake8/checker.py @@ -137,6 +137,14 @@ class Manager(object): if utils.fnmatch(filename, filename_patterns) ] + def run(self): + """Run checks. + + TODO(sigmavirus24): Get rid of this + """ + for checker in self.checkers: + checker.run_checks() + def is_path_excluded(self, path): # type: (str) -> bool """Check if a path is excluded. @@ -210,6 +218,7 @@ class FileChecker(object): def run_check(self, plugin, **arguments): """Run the check in a single plugin.""" + LOG.debug('Running %r with %r', plugin, arguments) self.processor.keyword_arguments_for(plugin.parameters, arguments) return plugin.execute(**arguments) @@ -263,7 +272,7 @@ class FileChecker(object): for token in file_processor.generate_tokens(): self.check_physical_eol(token) token_type, text = token[0:2] - processor.log_token(token) + processor.log_token(LOG, token) if token_type == tokenize.OP: parens = processor.count_parentheses(parens, text) elif parens == 0: @@ -298,7 +307,7 @@ class FileChecker(object): def handle_newline(self, token_type): """Handle the logic when encountering a newline token.""" if token_type == tokenize.NEWLINE: - self.check_logical() + self.run_logical_checks() self.processor.reset_blank_before() elif len(self.processor.tokens) == 1: # The physical line contains only this token. diff --git a/flake8/main/cli.py b/flake8/main/cli.py index 15eea8e..a2be97f 100644 --- a/flake8/main/cli.py +++ b/flake8/main/cli.py @@ -1,5 +1,6 @@ """Command-line implementation of flake8.""" import flake8 +from flake8 import checker from flake8 import defaults from flake8 import style_guide from flake8.options import aggregator @@ -181,10 +182,11 @@ class Application(object): self.check_plugins = None self.listening_plugins = None - self.formatting_plugigns = None + self.formatting_plugins = None self.formatter = None self.listener_trie = None self.guide = None + self.file_checker_manager = None self.options = None self.args = None @@ -242,6 +244,17 @@ class Application(object): self.options, self.listener_trie, self.formatter ) + def make_file_checker_manager(self): + # type: () -> NoneType + """Initialize our FileChecker Manager.""" + if self.file_checker_manager is None: + self.file_checker_manager = checker.Manager( + style_guide=self.guide, + arguments=self.args, + checker_plugins=self.check_plugins, + ) + self.file_checker_manager.make_checkers() + def run(self, argv=None): # type: (Union[NoneType, List[str]]) -> NoneType """Run our application.""" @@ -251,6 +264,8 @@ class Application(object): self.make_formatter() self.make_notifier() self.make_guide() + self.make_file_checker_manager() + self.file_checker_manager.run() def main(argv=None): diff --git a/flake8/processor.py b/flake8/processor.py index 062006d..88514e5 100644 --- a/flake8/processor.py +++ b/flake8/processor.py @@ -80,7 +80,7 @@ class FileProcessor(object): #: Total number of lines in the file self.total_lines = len(self.lines) #: Verbosity level of Flake8 - self.verbosity = options.verbosity + self.verbosity = options.verbose @contextlib.contextmanager def inside_multiline(self, line_number): @@ -302,10 +302,12 @@ def token_is_comment(token): def count_parentheses(current_parentheses_count, token_text): """Count the number of parentheses.""" + current_parentheses_count = current_parentheses_count or 0 if token_text in '([{': return current_parentheses_count + 1 elif token_text in '}])': return current_parentheses_count - 1 + return current_parentheses_count def log_token(log, token): diff --git a/setup.py b/setup.py index ec40eb6..9b66694 100644 --- a/setup.py +++ b/setup.py @@ -71,6 +71,7 @@ setuptools.setup( 'console_scripts': ['flake8 = flake8.main.cli:main'], 'flake8.extension': [ 'F = flake8.plugins.pyflakes:FlakesChecker', + 'pep8.tabs_or_spaces = pep8:tabs_or_spaces', ], 'flake8.report': [ 'default = flake8.formatting.default:Default',