Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconditionally store image path in POSIX notation in configuration #243

Merged
merged 10 commits into from
Oct 12, 2023
Prev Previous commit
Next Next commit
Enhance get_container_configuration() to report on a single container
This is a common use case in commands other than `containers_list`.
Albeit not strictly necessary (all configuration could be read
and processed first, and sub-selection could happen in user code),
it is a low-complexity change. Moreover, we envision more configuration
post-processing to happen in the future
(see #238). This
would change the cost assessment of loading everything upfront.
mih committed Oct 10, 2023
commit dbb2f914e43cf467858a2b7941ded686ae88908f
18 changes: 17 additions & 1 deletion datalad_container/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Collection of common utilities"""

from __future__ import annotations

from datalad.distribution.dataset import Dataset
from datalad.support.external_versions import external_versions

@@ -15,6 +17,7 @@ def get_container_command():

def get_container_configuration(
ds: Dataset,
name: str | None = None,
) -> dict:
"""Report all container-related configuration in a dataset
@@ -26,6 +29,10 @@ def get_container_configuration(
----------
ds: Dataset
Dataset instance to report configuration on.
name: str, optional
If given, the reported configuration will be limited to the container
with this exact name. In this case, only a single ``dict`` is returned,
not nested dictionaries.
Returns
-------
@@ -34,6 +41,11 @@ def get_container_configuration(
with their respective configuration items (with the
``datalad.containers.<container-name>.`` prefix removed from their
keys).
If `name` is given, only a single ``dict`` with the configuration
items of the matching container is returned (i.e., there will be no
outer ``dict`` with container names as keys).
If not (matching) container configuration exists, and empty dictionary
is returned.
"""
# all info is in the dataset config!
var_prefix = 'datalad.containers.'
@@ -44,6 +56,10 @@ def get_container_configuration(
continue
var_comps = var[len(var_prefix):].split('.')
cname = var_comps[0]
if name and name != cname:
# we are looking for a specific container's configuration
# and this is not it
continue
ccfgname = '.'.join(var_comps[1:])
if not ccfgname:
continue
@@ -53,4 +69,4 @@ def get_container_configuration(

containers[cname] = cinfo

return containers
return containers if name is None else containers.get(name, {})