mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-31 03:06:53 +00:00
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.
This commit is contained in:
parent
2e5c646d74
commit
49d1cf953c
1 changed files with 13 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue