diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-06-07 19:37:06 -0500 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-06-07 19:37:06 -0500 |
| commit | 49d1cf953c4cd2b6e5d839691f25ab0d2640bbbb (patch) | |
| tree | 9f0172c4a27802bbd101c7c87fbbd75f0aa2d213 | |
| parent | 2e5c646d7480c49637d106acfec439ef26426158 (diff) | |
| download | flake8-49d1cf953c4cd2b6e5d839691f25ab0d2640bbbb.tar.gz | |
Ensure that a file exists before processing it
If we don't check for a file's existence, then we'll find ourselves with
a hung subprocess due to an exception that happens with in it.
| -rw-r--r-- | flake8/checker.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/flake8/checker.py b/flake8/checker.py index eefc5fd..43482dd 100644 --- a/flake8/checker.py +++ b/flake8/checker.py @@ -214,12 +214,24 @@ class Manager(object): if paths is None: paths = self.arguments filename_patterns = self.options.filename + + # NOTE(sigmavirus24): Yes this is a little unsightly, but it's our + # best solution right now. + def should_create_file_checker(filename): + """Determine if we should create a file checker.""" + 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) for argument in paths for filename in utils.filenames_from(argument, self.is_path_excluded) - if utils.fnmatch(filename, filename_patterns) or filename == '-' + if should_create_file_checker(filename) ] def report(self): |
