Coverage for nilearn/_utils/path_finding.py: 24%

13 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-20 10:58 +0200

1"""Path finding utilities.""" 

2 

3import glob 

4from pathlib import Path 

5 

6from .helpers import stringify_path 

7 

8 

9def resolve_globbing(path): 

10 """Resolve globbing patterns in a path.""" 

11 path = stringify_path(path) 

12 if isinstance(path, str): 

13 expanded_path = Path(path).expanduser() 

14 path_list = sorted(glob.glob(str(expanded_path))) 

15 # Raise an error in case the list is empty. 

16 if len(path_list) == 0: 

17 raise ValueError(f"No files matching path: {path}") 

18 path_list = [Path(x) for x in path_list] 

19 path = path_list 

20 

21 return path