2020except ImportError :
2121 import json
2222
23- from .exceptions import InvalidConfiguration
23+ from .exceptions import InvalidConfiguration , MissingFile
2424
2525
2626CFG : Optional [dict ] = None
@@ -154,7 +154,15 @@ def find_configuration() -> Path: # TODO: add tests
154154 return Path (DEFAULT_CFG_PATH )
155155
156156
157- def get_file_location (location : str , base_path : Optional [str ]= None ) -> str :
157+ def get_file_location (location : str , base_path : Optional [str ]= None , exc : bool = True ) -> str :
158+ """
159+ Lookup a location of a file
160+
161+ :param location: relative or absolute file location or a filename
162+ :param base_path: base path used for resolving relative paths or filenames
163+ :param exc: Flag, raise an exception if the file could not be found/does not exists
164+ :return: resolved path to the given file location
165+ """
158166 if location .startswith ("aura.data." ): # Load file as a resource from aura package
159167 return location
160168
@@ -165,9 +173,14 @@ def get_file_location(location: str, base_path: Optional[str]=None) -> str:
165173 pth = Path (base_path ) / location
166174 if pth .is_file ():
167175 return str (pth )
176+ else :
177+ pth = location
168178
169- # TODO: use custom exception here so we can log as fatal and sys.exit(1)
170- raise InvalidConfiguration (f"Can't find configuration file `{ location } ` using base path `{ base_path } `" )
179+ if exc :
180+ # TODO: add location and base path directoly to the exception as variables for easy extraction
181+ raise MissingFile (f"Can't find configuration file `{ location } ` using base path `{ base_path } `" )
182+ else :
183+ return pth
171184
172185
173186def get_file_content (location : str , base_path : Optional [str ]= None ) -> str :
@@ -236,14 +249,14 @@ def load_config():
236249 sys .setrecursionlimit (int (rec_limit ))
237250
238251
239- def get_pypi_stats_path () -> Path :
252+ def get_pypi_stats_path (exc = True ) -> Path :
240253 pth = os .environ .get ("AURA_PYPI_STATS" , None ) or CFG ["aura" ]["pypi_stats" ]
241- return Path (get_file_location (pth , CFG_PATH ))
254+ return Path (get_file_location (pth , CFG_PATH , exc = exc ))
242255
243256
244- def get_reverse_dependencies_path () -> Path :
257+ def get_reverse_dependencies_path (exc = True ) -> Path :
245258 pth = os .environ .get ("AURA_REVERSE_DEPENDENCIES" , None ) or CFG ["aura" ]["reverse_dependencies" ]
246- return Path (get_file_location (pth , CFG_PATH ))
259+ return Path (get_file_location (pth , CFG_PATH , exc = exc ))
247260
248261
249262def iter_pypi_stats () -> Generator [dict , None , None ]:
@@ -253,6 +266,11 @@ def iter_pypi_stats() -> Generator[dict, None, None]:
253266 yield json .loads (line )
254267
255268
269+ def get_cache_mode () -> str :
270+ fallback = CFG .get ("cache" , {}).get ("mode" , "auto" )
271+ return os .environ .get ("AURA_CACHE_MODE" , fallback )
272+
273+
256274def get_maximum_archive_size () -> typing .Optional [int ] :
257275 """
258276 Get settings for a maximum archive file size that can be extracted
0 commit comments