Skip to content

Commit b88e1e8

Browse files
committed
use BIOIMAGEIO_NO_CACHE in export_resource_package
1 parent 1c366cf commit b88e1e8

File tree

1 file changed

+13
-2
lines changed
  • bioimageio/core/resource_io

1 file changed

+13
-2
lines changed

bioimageio/core/resource_io/io_.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import pathlib
33
from copy import deepcopy
4+
from tempfile import TemporaryDirectory
45
from typing import Dict, Optional, Sequence, Union
56
from zipfile import ZIP_DEFLATED, ZipFile
67

@@ -10,7 +11,12 @@
1011
from bioimageio.core.resource_io.nodes import ResourceDescription
1112
from bioimageio.spec import load_raw_resource_description
1213
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+
)
1420
from bioimageio.spec.shared.raw_nodes import ResourceDescription as RawResourceDescription
1521
from . import nodes
1622
from .utils import resolve_raw_resource_description, resolve_source
@@ -134,10 +140,15 @@ def _get_package_base_name(raw_rd: RawResourceDescription, weights_priority_orde
134140

135141

136142
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)
138147

148+
package_file_name = _get_package_base_name(raw_rd, weights_priority_order)
139149
cache_folder = BIOIMAGEIO_CACHE_PATH / "packages"
140150
cache_folder.mkdir(exist_ok=True, parents=True)
151+
141152
package_path = (cache_folder / package_file_name).with_suffix(".zip")
142153
max_cached_packages_with_same_name = 100
143154
for p in range(max_cached_packages_with_same_name):

0 commit comments

Comments
 (0)