Skip to content

Commit

Permalink
Merge pull request #536 from bioimage-io/fix_names_in_package
Browse files Browse the repository at this point in the history
improve cached file name for zenodo api changes
  • Loading branch information
FynnBe authored Oct 31, 2023
2 parents b2baad1 + 21de8c4 commit 4a05b37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bioimageio/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.4.9post4"
"version": "0.4.9post5"
}
11 changes: 8 additions & 3 deletions bioimageio/spec/shared/_resolve_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,12 @@ def _download_url(uri: raw_nodes.URI, output: typing.Optional[os.PathLike] = Non
local_path = pathlib.Path(output)
elif BIOIMAGEIO_USE_CACHE:
# todo: proper caching
local_path = BIOIMAGEIO_CACHE_PATH / uri.scheme / uri.authority / uri.path.strip("/") / uri.query
if uri.authority == "zenodo.org" and uri.path.startswith("/api/records/") and uri.path.endswith("/content"):
p = uri.path[: -len("/content")].strip("/")
else:
p = uri.path.strip("/")

local_path = BIOIMAGEIO_CACHE_PATH / uri.scheme / uri.authority / p / uri.query
else:
tmp_dir = TemporaryDirectory()
no_cache_tmp_list.append(tmp_dir) # keep temporary file until process ends
Expand Down Expand Up @@ -462,9 +467,9 @@ def _download_url(uri: raw_nodes.URI, output: typing.Optional[os.PathLike] = Non
total_size = int(r.headers.get("content-length", 0))
block_size = 1024 # 1 Kibibyte
if pbar:
t = pbar(total=total_size, unit="iB", unit_scale=True, desc=uri.path.split("/")[-1])
t = pbar(total=total_size, unit="iB", unit_scale=True, desc=local_path.name)
else:
t = tqdm(total=total_size, unit="iB", unit_scale=True, desc=uri.path.split("/")[-1])
t = tqdm(total=total_size, unit="iB", unit_scale=True, desc=local_path.name)
tmp_path = local_path.with_suffix(f"{local_path.suffix}.part")
with tmp_path.open("wb") as f:
for data in r.iter_content(block_size):
Expand Down

0 comments on commit 4a05b37

Please sign in to comment.