From 6e756458f605c654181b80d8528201ad194df607 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Tue, 10 Oct 2023 11:59:59 +0200 Subject: [PATCH] Replace custom configuration definition with standard approach Since v0.16 datalad provides a `register_config()` helper for extensions to inject their own configuration into the central registry. This changeset replaces the previous custom implementation with this standard approach. It has not consequences re user behavior. An additional benefit is that this configuration is now also user-accessible, including a basic documentation: ```py >>> import datalad_container >>> from datalad.api import configuration >>> configuration('dump', 'datalad.containers.location') datalad.containers.location=.datalad/environments [{'action': 'dump_configuration', 'refds': '/home/mih/hacking/datalad/container', 'name': 'datalad.containers.location', 'value': '.datalad/environments', 'purpose': 'Container location', 'description': 'path within the dataset where to store containers', 'value_type': constraint:str, 'path': '/home/mih/hacking/datalad/container', 'status': 'ok'}] ``` Closes #239 --- datalad_container/__init__.py | 14 ++++++++++++++ datalad_container/containers_add.py | 10 ---------- datalad_container/definitions.py | 13 ------------- 3 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 datalad_container/definitions.py diff --git a/datalad_container/__init__.py b/datalad_container/__init__.py index 55981995..1cee45c6 100644 --- a/datalad_container/__init__.py +++ b/datalad_container/__init__.py @@ -47,5 +47,19 @@ ] ) +from datalad.support.extensions import register_config +from os.path import join as opj +from datalad.support.constraints import EnsureStr + +register_config( + 'datalad.containers.location', + 'Container location', + description='path within the dataset where to store containers', + type=EnsureStr(), + default=opj(".datalad", "environments"), + dialog='question', + scope='dataset', +) + from . import _version __version__ = _version.get_versions()['version'] diff --git a/datalad_container/containers_add.py b/datalad_container/containers_add.py index 3840e05a..c243e57c 100644 --- a/datalad_container/containers_add.py +++ b/datalad_container/containers_add.py @@ -22,8 +22,6 @@ from datalad.support.exceptions import InsufficientArgumentsError from datalad.interface.results import get_status_dict -from .definitions import definitions - lgr = logging.getLogger("datalad.containers.containers_add") # The DataLad special remote has built-in support for Singularity Hub URLs. Let @@ -232,20 +230,12 @@ def __call__(name, url=None, dataset=None, call_fmt=None, image=None, if not image: loc_cfg_var = "datalad.containers.location" - # TODO: We should provide an entry point (or sth similar) for extensions - # to get config definitions into the ConfigManager. In other words an - # easy way to extend definitions in datalad's common_cfgs.py. container_loc = \ ds.config.obtain( loc_cfg_var, - where=definitions[loc_cfg_var]['destination'], # if not False it would actually modify the # dataset config file -- undesirable store=False, - default=definitions[loc_cfg_var]['default'], - dialog_type=definitions[loc_cfg_var]['ui'][0], - valtype=definitions[loc_cfg_var]['type'], - **definitions[loc_cfg_var]['ui'][1] ) image = op.join(ds.path, container_loc, name, 'image') else: diff --git a/datalad_container/definitions.py b/datalad_container/definitions.py deleted file mode 100644 index 0395604e..00000000 --- a/datalad_container/definitions.py +++ /dev/null @@ -1,13 +0,0 @@ -import os.path as op -from datalad.support.constraints import EnsureStr - -definitions = { - 'datalad.containers.location': { - 'ui': ('question', { - 'title': 'Container location', - 'text': 'path within the dataset where to store containers'}), - 'default': op.join(".datalad", "environments"), - 'type': EnsureStr(), - 'destination': 'dataset' - }, -}