Skip to content

Commit 8345acd

Browse files
committed
update to BIOIMAGEIO_USE_CACHE env var
1 parent 6125efc commit 8345acd

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

bioimageio/core/resource_io/io_.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from bioimageio.spec.shared import raw_nodes
1414
from bioimageio.spec.shared.common import (
1515
BIOIMAGEIO_CACHE_PATH,
16-
BIOIMAGEIO_NO_CACHE,
16+
BIOIMAGEIO_USE_CACHE,
1717
get_class_name_from_type,
1818
no_cache_tmp_list,
1919
)
@@ -140,26 +140,26 @@ def _get_package_base_name(raw_rd: RawResourceDescription, weights_priority_orde
140140

141141

142142
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
157155
else:
158-
break
156+
raise FileExistsError(
157+
f"Already caching {max_cached_packages_with_same_name} versions of {cache_folder / package_file_name}!"
158+
)
159159
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"
163163

164164
return package_path
165165

tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_cli_package(unet2d_nuclei_broad_model, tmp_path):
2727

2828
def test_cli_package_wo_cache(unet2d_nuclei_broad_model):
2929
env = os.environ.copy()
30-
env["BIOIMAGEIO_NO_CACHE"] = "True"
30+
env["BIOIMAGEIO_USE_CACHE"] = "false"
3131
ret = run_subprocess(["bioimageio", "package", unet2d_nuclei_broad_model], env=env)
3232
assert ret.returncode == 0, ret.stdout
3333

0 commit comments

Comments
 (0)