@@ -21,7 +21,7 @@ def fetch_parameter(self, param_name: str) -> Path:
2121 def fetch_workspace_file (self , file_name : str ) -> Path :
2222 return self .workspace_collector .fetch (file_name )
2323
24- def fetch (self , name : str ) -> Path :
24+ def fetch (self , name : str ) -> Path | str :
2525 try :
2626 return self .fetch_parameter (name )
2727 except (KeyError , FileNotFoundError ):
@@ -38,8 +38,11 @@ def __init__(self):
3838 self .paths : dict [str , Path ] = {}
3939
4040 def collect (self ):
41- for dataset_id in os .listdir (EC .cosmotech .dataset_absolute_path ):
42- for r , d , f in os .walk (Path (EC .cosmotech .dataset_absolute_path ) / dataset_id ):
41+ base_path = Path (EC .cosmotech .dataset_absolute_path )
42+ for dataset_id in os .listdir (base_path ):
43+ if not (base_path / dataset_id ).is_dir ():
44+ continue
45+ for r , d , f in os .walk (base_path / dataset_id ):
4346 for dataset_name in f :
4447 path = Path (r ) / dataset_name
4548 self .paths [dataset_name ] = path
@@ -89,15 +92,18 @@ def read_parameters_json(self):
8992 self .parameters [parameter ["parameterId" ]] = parameter ["value" ]
9093
9194 def collect (self ):
92- for dataset_id in os .listdir (EC .cosmotech .parameters_absolute_path ):
93- for r , d , f in os .walk (Path (EC .cosmotech .parameters_absolute_path ) / dataset_id ):
95+ base_path = Path (EC .cosmotech .parameters_absolute_path )
96+ for dataset_id in os .listdir (base_path ):
97+ if not (base_path / dataset_id ).is_dir ():
98+ continue
99+ for r , d , f in os .walk (base_path / dataset_id ):
94100 for file_name in f :
95101 path = Path (r ) / file_name
96102 param_name = path .parent .name
97103 self .paths [param_name ] = path
98104 self .paths [path .stem ] = path
99105
100- def fetch_parameter (self , param_name : str ) -> Path :
106+ def fetch_parameter (self , param_name : str ) -> Path | str :
101107 # lazy collection to avoid unnecessary json loading
102108 if not self .parameters :
103109 self .read_parameters_json ()
@@ -111,7 +117,7 @@ def fetch_file_path(self, param_name: str) -> Path:
111117 return self .paths [param_name ]
112118 raise FileNotFoundError (f"File for { param_name } not found in { EC .cosmotech .parameters_absolute_path } ." )
113119
114- def fetch (self , param_name : str ) -> Path :
120+ def fetch (self , param_name : str ) -> Path | str :
115121 try :
116122 return self .fetch_parameter (param_name )
117123 except KeyError :
0 commit comments