Skip to content

Commit

Permalink
refactor: move check to class, expand error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnighter committed Apr 21, 2022
1 parent 1882e87 commit 893fc9a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 10 additions & 7 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os
import re
import requests
import rich.console
import rich.logging
import rich.traceback
Expand Down Expand Up @@ -693,15 +692,19 @@ def mulled(specifications, build_number):
that image, this command can generate it for you.
"""
image_name = nf_core.modules.mulled.MulledImageNameGenerator.generate_image_name(
nf_core.modules.mulled.MulledImageNameGenerator.parse_targets(specifications), build_number=build_number
from nf_core.modules.mulled import MulledImageNameGenerator

image_name = MulledImageNameGenerator.generate_image_name(
MulledImageNameGenerator.parse_targets(specifications), build_number=build_number
)
print(image_name)
response = requests.get(f"https://quay.io/biocontainers/{image_name}/", allow_redirects=True)
if response.status_code != 200:
if not MulledImageNameGenerator.image_exists(image_name):
log.error(
"The generated multi-tool container image does not seem to exist yet. Are you sure that you provided the "
"right combination of tools and versions?"
"The generated multi-tool container image name does not seem to exist yet. Please double check that your "
"provided combination of tools and versions exists in the file:\n"
"https://github.com/BioContainers/multi-package-containers/blob/master/combinations/hash.tsv\n"
"If it does not, please add your desired combination as detailed at:\n"
"https://github.com/BioContainers/multi-package-containers\n"
)
sys.exit(1)

Expand Down
8 changes: 8 additions & 0 deletions nf_core/modules/mulled.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from packaging.version import Version, InvalidVersion
from typing import Iterable, Tuple, List

import requests
from galaxy.tool_util.deps.mulled.util import build_target, v2_image_name


Expand Down Expand Up @@ -57,3 +58,10 @@ def generate_image_name(cls, targets: Iterable[Tuple[str, str]], build_number: i
"""
return v2_image_name([build_target(name, version) for name, version in targets], image_build=str(build_number))

@classmethod
def image_exists(cls, image_name: str) -> bool:
"""Check whether a given BioContainers image name exists via a call to the quay.io API."""
response = requests.get(f"https://quay.io/biocontainers/{image_name}/", allow_redirects=True)
log.debug(response.text)
return response.status_code == 200

0 comments on commit 893fc9a

Please sign in to comment.