glenn-jocher commited on
Commit
5a8e434
1 Parent(s): 7933832

Scope `check_file()` search space (#4933)

Browse files

`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.

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