Skip to content

Commit 740b1bb

Browse files
authored
Merge pull request #635 from bioimage-io/skip_existing_thumbnails
skip recreating existing thumbnails
2 parents 102114b + 67a5a37 commit 740b1bb

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

collection_rdf_template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config:
3939
branch: master
4040
collection_file_name: manifest.bioimage.io.yaml
4141
- id: deepimagej
42-
repository: deepimagej/models
42+
repository: fynnbe/models
4343
branch: master
4444
collection_file_name: manifest.bioimage.io.yaml
4545
test_summaries:

scripts/generate_collection_rdf_and_thumbnails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def main(
141141
if links:
142142
summary["links"] = links
143143

144-
deploy_thumbnails(summary, dist, r.resource_id, version_id)
144+
deploy_thumbnails(summary, dist, gh_pages, r.resource_id, version_id)
145145
rdf["collection"].append(summary)
146146
type_ = latest_version.get("type", "unknown")
147147
n_accepted[type_] = n_accepted.get(type_, 0) + 1

scripts/utils.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import warnings
77
from hashlib import sha256
88
from itertools import product
9-
from pathlib import Path
9+
from pathlib import Path, PurePosixPath
1010
from typing import Any, Dict, Generator, List, Optional, Sequence, Tuple, Union
11+
from urllib.parse import urlsplit
1112

1213
import numpy
1314
import requests
@@ -124,7 +125,7 @@ def resolve_partners(
124125
assert isinstance(partner_collection, Collection)
125126
except Exception as e:
126127
warnings.warn(
127-
f"Invalid partner source {partner['source']} (Cannot update to format {current_format}): {e}"
128+
f"Invalid partner source {partner.get('source')} (Cannot update to format {current_format}): {e}"
128129
)
129130
ignored_partners.add(f"partner[{idx}]")
130131
continue
@@ -385,43 +386,42 @@ def load_yaml_dict(path: Path, raise_missing_keys: Sequence[str]) -> Optional[Di
385386
return data
386387

387388

388-
def downsize_image(image_path: Path, dist: Path, size: Tuple[int, int]):
389+
def downsize_image(image_path: Path, output_path: Path, size: Tuple[int, int]):
389390
"""downsize or copy an image"""
390391
from PIL import Image
391392

392-
output_path = dist / f"{image_path.stem}.png"
393393
try:
394394
with Image.open(image_path) as img:
395395
img.thumbnail(size)
396396
img.save(output_path, "PNG")
397397
except Exception as e:
398398
warnings.warn(str(e))
399-
output_path = output_path.with_name(image_path.name)
400399
shutil.copy(image_path, output_path)
401400

402-
return output_path
403401

404-
405-
def deploy_thumbnails(rdf_like: Dict[str, Any], dist: Path, resource_id: str, version_id: str) -> None:
402+
def deploy_thumbnails(rdf_like: Dict[str, Any], dist: Path, gh_pages: Path, resource_id: str, version_id: str) -> None:
406403
import pooch
407404

408405
dist /= f"rdfs/{resource_id}/{version_id}"
406+
gh_pages /= f"rdfs/{resource_id}/{version_id}"
409407
dist.mkdir(exist_ok=True, parents=True)
410408
covers: Union[Any, List[Any]] = rdf_like.get("covers")
411409
if isinstance(covers, list):
412410
for i, cover_url in enumerate(covers):
413411
if not isinstance(cover_url, str) or cover_url.startswith(DEPLOYED_BASE_URL):
414412
continue # invalid or already cached
415413

416-
try:
417-
downloaded_cover = Path(pooch.retrieve(cover_url, None)) # type: ignore
418-
except Exception as e:
419-
warnings.warn(str(e))
420-
continue
414+
cover_file_name = PurePosixPath(urlsplit(cover_url).path).name
415+
if not (gh_pages / cover_file_name).exists():
416+
try:
417+
downloaded_cover = Path(pooch.retrieve(cover_url, None)) # type: ignore
418+
except Exception as e:
419+
warnings.warn(str(e))
420+
continue
421421

422-
resized_cover = downsize_image(downloaded_cover, dist, size=(600, 340))
422+
downsize_image(downloaded_cover, dist / cover_file_name, size=(600, 340))
423423

424-
rdf_like["covers"][i] = f"{DEPLOYED_BASE_URL}/rdfs/{resource_id}/{version_id}/{resized_cover.name}"
424+
rdf_like["covers"][i] = f"{DEPLOYED_BASE_URL}/rdfs/{resource_id}/{version_id}/{cover_file_name}"
425425

426426
badges: Union[Any, List[Union[Any, Dict[Any, Any]]]] = rdf_like.get("badges")
427427
if isinstance(badges, list):

0 commit comments

Comments
 (0)