From 49d1cf953c4cd2b6e5d839691f25ab0d2640bbbb Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 7 Jun 2016 19:37:06 -0500 Subject: [PATCH] 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. --- flake8/checker.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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):