|
1 | 1 | import os |
2 | 2 | import pathlib |
3 | 3 | from copy import deepcopy |
| 4 | +from tempfile import TemporaryDirectory |
4 | 5 | from typing import Dict, Optional, Sequence, Union |
5 | 6 | from zipfile import ZIP_DEFLATED, ZipFile |
6 | 7 |
|
|
10 | 11 | from bioimageio.core.resource_io.nodes import ResourceDescription |
11 | 12 | from bioimageio.spec import load_raw_resource_description |
12 | 13 | from bioimageio.spec.shared import raw_nodes |
13 | | -from bioimageio.spec.shared.common import BIOIMAGEIO_CACHE_PATH, get_class_name_from_type |
| 14 | +from bioimageio.spec.shared.common import ( |
| 15 | + BIOIMAGEIO_CACHE_PATH, |
| 16 | + BIOIMAGEIO_NO_CACHE, |
| 17 | + get_class_name_from_type, |
| 18 | + no_cache_tmp_list, |
| 19 | +) |
14 | 20 | from bioimageio.spec.shared.raw_nodes import ResourceDescription as RawResourceDescription |
15 | 21 | from . import nodes |
16 | 22 | from .utils import resolve_raw_resource_description, resolve_source |
@@ -134,10 +140,15 @@ def _get_package_base_name(raw_rd: RawResourceDescription, weights_priority_orde |
134 | 140 |
|
135 | 141 |
|
136 | 142 | def _get_tmp_package_path(raw_rd: RawResourceDescription, weights_priority_order: Optional[Sequence[str]]): |
137 | | - package_file_name = _get_package_base_name(raw_rd, weights_priority_order) |
| 143 | + if BIOIMAGEIO_NO_CACHE: |
| 144 | + tmp_dir = TemporaryDirectory() |
| 145 | + no_cache_tmp_list.append(tmp_dir) |
| 146 | + return pathlib.Path(tmp_dir.name) |
138 | 147 |
|
| 148 | + package_file_name = _get_package_base_name(raw_rd, weights_priority_order) |
139 | 149 | cache_folder = BIOIMAGEIO_CACHE_PATH / "packages" |
140 | 150 | cache_folder.mkdir(exist_ok=True, parents=True) |
| 151 | + |
141 | 152 | package_path = (cache_folder / package_file_name).with_suffix(".zip") |
142 | 153 | max_cached_packages_with_same_name = 100 |
143 | 154 | for p in range(max_cached_packages_with_same_name): |
|
0 commit comments