diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-20 19:28:13 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-20 19:28:13 -0500 |
| commit | a1fdb5a2b5934ef5629df2335b2d495ba5252812 (patch) | |
| tree | f95ce2e638dc3bf722cd4c6a615dda8d29e66c58 /src/flake8/checker.py | |
| parent | 7934f8dce2fc1c5d8da374a3c7435d36f9526b0b (diff) | |
| download | flake8-a1fdb5a2b5934ef5629df2335b2d495ba5252812.tar.gz | |
Fix up merge request 78
This simplifies the changes, reduces the scope of refactors apparently
for refactoring's sake and ensures that the internals are reasonable.
It also airs on the side of preserving information rather than
discarding or overwriting it.
Diffstat (limited to 'src/flake8/checker.py')
| -rw-r--r-- | src/flake8/checker.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 7c70ace..ba412e3 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -234,15 +234,14 @@ class Manager(object): :rtype: bool """ + if path == '-': + if self.options.stdin_display_name == 'stdin': + return False + path = self.options.stdin_display_name + exclude = self.options.exclude if not exclude: return False - if path == '-': - # stdin, use display name to check exclusion, if present - path = self.options.stdin_display_name - if path is None: - LOG.debug("unnamed stdin has not been excluded") - return False basename = os.path.basename(path) if utils.fnmatch(basename, exclude): LOG.debug('"%s" has been excluded', basename) @@ -269,14 +268,15 @@ class Manager(object): # best solution right now. def should_create_file_checker(filename): """Determine if we should create a file checker.""" - return ( - filename == '-' or # stdin - utils.fnmatch(filename, filename_patterns) and - os.path.exists(filename) + matches_filename_patterns = utils.fnmatch( + filename, filename_patterns ) + is_stdin = filename == '-' + file_exists = os.path.exists(filename) + return (file_exists and matches_filename_patterns) or is_stdin self.checkers = [ - FileChecker(filename, self.checks, self.style_guide) + FileChecker(filename, self.checks, self.options) for argument in paths for filename in utils.filenames_from(argument, self.is_path_excluded) @@ -299,7 +299,7 @@ class Manager(object): results_reported = results_found = 0 for checker in self.checkers: results = sorted(checker.results, key=lambda tup: (tup[2], tup[3])) - results_reported += self._handle_results(checker.filename, + results_reported += self._handle_results(checker.display_name, results) results_found += len(results) return (results_found, results_reported) @@ -320,9 +320,9 @@ class Manager(object): final_results[filename] = results for checker in self.checkers: - filename = checker.filename + filename = checker.display_name checker.results = sorted(final_results.get(filename, []), - key=lambda tup: (tup[1], tup[2])) + key=lambda tup: (tup[2], tup[2])) def run_serial(self): """Run the checkers in serial.""" @@ -384,7 +384,7 @@ class Manager(object): class FileChecker(object): """Manage running checks for a file and aggregate the results.""" - def __init__(self, filename, checks, style_guide): + def __init__(self, filename, checks, options): """Initialize our file checker. :param str filename: @@ -393,26 +393,26 @@ class FileChecker(object): The plugins registered to check the file. :type checks: flake8.plugins.manager.Checkers - :param style_guide: - The initialized StyleGuide for this particular run. - :type style_guide: - flake8.style_guide.StyleGuide + :param options: + Parsed option values from config and command-line. + :type options: + optparse.Values """ + self.options = options + self.filename = filename self.checks = checks - self.style_guide = style_guide self.results = [] - self.processor = self._make_processor(filename) - self.filename = self.processor.filename + self.processor = self._make_processor() + self.display_name = self.processor.filename self.statistics = { 'tokens': 0, 'logical lines': 0, 'physical lines': len(self.processor.lines), } - def _make_processor(self, filename): + def _make_processor(self): try: - return processor.FileProcessor(filename, - self.style_guide.options) + return processor.FileProcessor(self.filename, self.options) except IOError: # If we can not read the file due to an IOError (e.g., the file # does not exist or we do not have the permissions to open it) |
