Scope check_file() search space (#4933)

`check_file()` is now limited to searching opt-in directories: /data, /models, /utils. This prevents large non-project directories like /.git and /venv from being searched, which may cause `check_file()` to slow significantly.
This commit is contained in:
Glenn Jocher 2021-09-26 17:11:46 -07:00 committed by GitHub
parent 793383232f
commit 5a8e4343d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -315,7 +315,9 @@ def check_file(file, suffix=''):
assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check
return file
else: # search
files = glob.glob('./**/' + file, recursive=True) # find file
files = []
for d in 'data', 'models', 'utils': # search directories
files.extend(glob.glob(str(ROOT / d / '**' / file), recursive=True)) # find file
assert len(files), f'File not found: {file}' # assert file was found
assert len(files) == 1, f"Multiple files match '{file}', specify exact path: {files}" # assert unique
return files[0] # return file