1212
1313import pooch
1414import tomli
15+ from filelock import FileLock
1516
1617import modflow_devtools
1718
2627
2728# set up the pooch
2829FETCHERS = {}
29- REGISTRY : dict [ str , str ] = {}
30- MODELMAP : dict [ str , list [ str ]] = {}
31- EXAMPLES : dict [ str , list [ str ]] = {}
30+ REGISTRY : dict = {}
31+ MODELMAP : dict = {}
32+ EXAMPLES : dict = {}
3233POOCH = pooch .create (
3334 path = pooch .os_cache (modflow_devtools .__name__ .replace ("_" , "-" )),
3435 base_url = BASE_URL ,
@@ -42,12 +43,13 @@ def _fetch_files():
4243 return [Path (POOCH .fetch (fname )) for fname in file_names ]
4344
4445 def _fetch_zip (zip_name ):
45- return [
46- Path (f )
47- for f in POOCH .fetch (
48- zip_name , processor = pooch .Unzip (members = MODELMAP [model_name ])
49- )
50- ]
46+ with FileLock (f"{ zip_name } .lock" ):
47+ return [
48+ Path (f )
49+ for f in POOCH .fetch (
50+ zip_name , processor = pooch .Unzip (members = MODELMAP [model_name ])
51+ )
52+ ]
5153
5254 urls = [POOCH .registry [fname ] for fname in file_names ]
5355 if not any (url for url in urls ) or set (urls ) == {f"{ BASE_URL } /{ ZIP_NAME } " }:
@@ -62,10 +64,11 @@ def _fetch_zip(zip_name):
6264 with pkg_resources .open_binary (
6365 REGISTRY_ANCHOR , REGISTRY_FILE_NAME
6466 ) as registry_file :
65- registry = tomli .load (registry_file )
66- urls = {k : v ["url" ] for k , v in registry .items () if v .get ("url" , None )}
67- registry = {k : v .get ("hash" , None ) for k , v in registry .items ()}
68- POOCH .registry = registry
67+ REGISTRY = tomli .load (registry_file )
68+ # extract urls then drop them, leaving a direct map of name to hash
69+ urls = {k : v ["url" ] for k , v in REGISTRY .items () if v .get ("url" , None )}
70+ REGISTRY = {k : v .get ("hash" , None ) for k , v in REGISTRY .items ()}
71+ POOCH .registry = REGISTRY
6972 POOCH .urls = urls
7073except : # noqa: E722
7174 warn (
@@ -105,7 +108,7 @@ def get_examples() -> dict[str, list[str]]:
105108
106109
107110def get_registry () -> dict [str , str ]:
108- return POOCH . registry
111+ return REGISTRY
109112
110113
111114def list_models () -> list [str ]:
0 commit comments