From 5a8e4343d80de4ece38cdb5807a7187ec937c57c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 26 Sep 2021 17:11:46 -0700 Subject: [PATCH] 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. --- utils/general.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 3c5cbff13d55..00bafb1e9537 100755 --- a/utils/general.py +++ b/utils/general.py @@ -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