Skip to content

Commit

Permalink
RF containers_add to use get_container_configuration()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mih committed Oct 10, 2023
1 parent 9b95b78 commit 8499756
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions datalad_container/containers_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -219,16 +220,16 @@ 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,
status="impossible",
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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8499756

Please sign in to comment.