|
13 | 13 | from bioimageio.spec.shared import raw_nodes |
14 | 14 | from bioimageio.spec.shared.common import ( |
15 | 15 | BIOIMAGEIO_CACHE_PATH, |
16 | | - BIOIMAGEIO_NO_CACHE, |
| 16 | + BIOIMAGEIO_USE_CACHE, |
17 | 17 | get_class_name_from_type, |
18 | 18 | no_cache_tmp_list, |
19 | 19 | ) |
@@ -140,26 +140,26 @@ def _get_package_base_name(raw_rd: RawResourceDescription, weights_priority_orde |
140 | 140 |
|
141 | 141 |
|
142 | 142 | def _get_tmp_package_path(raw_rd: RawResourceDescription, weights_priority_order: Optional[Sequence[str]]): |
143 | | - if BIOIMAGEIO_NO_CACHE: |
144 | | - tmp_dir = TemporaryDirectory() |
145 | | - no_cache_tmp_list.append(tmp_dir) |
146 | | - return pathlib.Path(tmp_dir.name) / "file" |
147 | | - |
148 | | - package_file_name = _get_package_base_name(raw_rd, weights_priority_order) |
149 | | - cache_folder = BIOIMAGEIO_CACHE_PATH / "packages" |
150 | | - cache_folder.mkdir(exist_ok=True, parents=True) |
151 | | - |
152 | | - package_path = (cache_folder / package_file_name).with_suffix(".zip") |
153 | | - max_cached_packages_with_same_name = 100 |
154 | | - for p in range(max_cached_packages_with_same_name): |
155 | | - if package_path.exists(): |
156 | | - package_path = (cache_folder / f"{package_file_name}p{p}").with_suffix(".zip") |
| 143 | + if BIOIMAGEIO_USE_CACHE: |
| 144 | + package_file_name = _get_package_base_name(raw_rd, weights_priority_order) |
| 145 | + cache_folder = BIOIMAGEIO_CACHE_PATH / "packages" |
| 146 | + cache_folder.mkdir(exist_ok=True, parents=True) |
| 147 | + |
| 148 | + package_path = (cache_folder / package_file_name).with_suffix(".zip") |
| 149 | + max_cached_packages_with_same_name = 100 |
| 150 | + for p in range(max_cached_packages_with_same_name): |
| 151 | + if package_path.exists(): |
| 152 | + package_path = (cache_folder / f"{package_file_name}p{p}").with_suffix(".zip") |
| 153 | + else: |
| 154 | + break |
157 | 155 | else: |
158 | | - break |
| 156 | + raise FileExistsError( |
| 157 | + f"Already caching {max_cached_packages_with_same_name} versions of {cache_folder / package_file_name}!" |
| 158 | + ) |
159 | 159 | else: |
160 | | - raise FileExistsError( |
161 | | - f"Already caching {max_cached_packages_with_same_name} versions of {cache_folder / package_file_name}!" |
162 | | - ) |
| 160 | + tmp_dir = TemporaryDirectory() |
| 161 | + no_cache_tmp_list.append(tmp_dir) |
| 162 | + package_path = pathlib.Path(tmp_dir.name) / "file" |
163 | 163 |
|
164 | 164 | return package_path |
165 | 165 |
|
|
0 commit comments