From 849975632aa60176cf451dd3862960d1a7238810 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Tue, 10 Oct 2023 10:00:57 +0200 Subject: [PATCH] RF `containers_add` to use `get_container_configuration()` This is the last change for establishing `get_container_configuration()` as the single code piece for reading container documentation. This opens the door for implementing on-read normalization of configuration items, such as the image path. Closes #238 --- datalad_container/containers_add.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/datalad_container/containers_add.py b/datalad_container/containers_add.py index 3840e05a..608407d7 100644 --- a/datalad_container/containers_add.py +++ b/datalad_container/containers_add.py @@ -22,6 +22,7 @@ from datalad.support.exceptions import InsufficientArgumentsError from datalad.interface.results import get_status_dict +from .utils import get_container_configuration from .definitions import definitions lgr = logging.getLogger("datalad.containers.containers_add") @@ -205,8 +206,8 @@ def __call__(name, url=None, dataset=None, call_fmt=None, image=None, "Container names can only contain alphanumeric characters " "and '-', got: '{}'".format(name)) - cfgbasevar = "datalad.containers.{}".format(name) - if cfgbasevar + ".image" in ds.config: + container_cfg = get_container_configuration(ds, name) + if 'image' in container_cfg: if not update: yield get_status_dict( action="containers_add", ds=ds, logger=lgr, @@ -219,7 +220,7 @@ def __call__(name, url=None, dataset=None, call_fmt=None, image=None, if not (url or image or call_fmt): # No updated values were provided. See if an update url is # configured (currently relevant only for Singularity Hub). - url = ds.config.get(cfgbasevar + ".updateurl") + url = container_cfg.get("updateurl") if not url: yield get_status_dict( action="containers_add", ds=ds, logger=lgr, @@ -227,8 +228,8 @@ def __call__(name, url=None, dataset=None, call_fmt=None, image=None, message="No values to update specified") return - call_fmt = call_fmt or ds.config.get(cfgbasevar + ".cmdexec") - image = image or ds.config.get(cfgbasevar + ".image") + call_fmt = call_fmt or container_cfg.get("cmdexec") + image = image or container_cfg.get("image") if not image: loc_cfg_var = "datalad.containers.location" @@ -329,6 +330,7 @@ def __call__(name, url=None, dataset=None, call_fmt=None, image=None, return # store configs + cfgbasevar = "datalad.containers.{}".format(name) if imgurl != url: # store originally given URL, as it resolves to something # different and maybe can be used to update the container