diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ce10b3ddc..e8560356b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ - Fix inconsistencies in the `--save-diff` flag `nf-core modules update`. Refactor `nf-core modules update` ([#1536](https://github.com/nf-core/tools/pull/1536)) - Fix bug in `ModulesJson.check_up_to_date` causing it to ask for the remote of local modules - Make `nf-core modules update --save-diff` work when files were created or removed ([#1694](https://github.com/nf-core/tools/issues/1694)) +- Get the latest common build for Docker and Singularity containers of a module ([#1702](https://github.com/nf-core/tools/pull/1702)) - Add short option for `--no-pull` option in `nf-core modules` ## [v2.4.1 - Cobolt Koala Patch](https://github.com/nf-core/tools/releases/tag/2.4) - [2022-05-16] diff --git a/nf_core/utils.py b/nf_core/utils.py index df5e3d5fcb..9881ed0664 100644 --- a/nf_core/utils.py +++ b/nf_core/utils.py @@ -701,16 +701,30 @@ def get_tag_date(tag_date): images = response.json()["images"] singularity_image = None docker_image = None + all_docker = {} + all_singularity = {} for img in images: - # Get most recent Docker and Singularity image + # Get all Docker and Singularity images if img["image_type"] == "Docker": - modification_date = get_tag_date(img["updated"]) - if not docker_image or modification_date > get_tag_date(docker_image["updated"]): - docker_image = img - if img["image_type"] == "Singularity": - modification_date = get_tag_date(img["updated"]) - if not singularity_image or modification_date > get_tag_date(singularity_image["updated"]): - singularity_image = img + # Obtain version and build + match = re.search(r"(?::)+([A-Za-z\d\-_.]+)", img["image_name"]) + if match is not None: + all_docker[match.group(1)] = {"date": get_tag_date(img["updated"]), "image": img} + elif img["image_type"] == "Singularity": + # Obtain version and build + match = re.search(r"(?::)+([A-Za-z\d\-_.]+)", img["image_name"]) + if match is not None: + all_singularity[match.group(1)] = {"date": get_tag_date(img["updated"]), "image": img} + # Obtain common builds from Docker and Singularity images + common_keys = list(all_docker.keys() & all_singularity.keys()) + current_date = None + for k in common_keys: + # Get the most recent common image + date = max(all_docker[k]["date"], all_docker[k]["date"]) + if docker_image is None or current_date < date: + docker_image = all_docker[k]["image"] + singularity_image = all_singularity[k]["image"] + current_date = date return docker_image["image_name"], singularity_image["image_name"] except TypeError: raise LookupError(f"Could not find docker or singularity container for {package}")