diff --git a/datalad_registry_client/get_urls.py b/datalad_registry_client/get_urls.py index 5ed04114..8b04e0f9 100644 --- a/datalad_registry_client/get_urls.py +++ b/datalad_registry_client/get_urls.py @@ -5,7 +5,6 @@ import logging from typing import Optional -from datalad import cfg from datalad.interface.base import Interface, build_doc, eval_results from datalad.interface.results import get_status_dict from datalad.support.constraints import EnsureNone, EnsureStr @@ -13,11 +12,10 @@ import requests from yarl import URL -from . import DEFAULT_BASE_ENDPOINT +from datalad_registry.blueprints.api import DATASET_URLS_PATH -# The path of the dataset URLs resource on the DataLad Registry instance relative to -# the base API endpoint of the instance. -_DATASET_URLS_PATH = "dataset-urls" +from . import DEFAULT_BASE_ENDPOINT +from .utils import get_base_endpoint lgr = logging.getLogger("datalad.registry.get_urls") @@ -66,13 +64,11 @@ class RegistryGetURLs(Interface): def __call__(cache_path: Optional[str] = None, base_endpoint: Optional[str] = None): from datalad_registry.blueprints.api.dataset_urls.models import DatasetURLPage - # Set `base_endpoint` to the default if it is not provided. + # Set `base_endpoint` based on configuration if it is not provided. if base_endpoint is None: - base_endpoint = cfg.get( - "datalad_registry.base_endpoint", DEFAULT_BASE_ENDPOINT - ) + base_endpoint = get_base_endpoint() - endpoint = URL(base_endpoint) / _DATASET_URLS_PATH + endpoint = URL(base_endpoint) / DATASET_URLS_PATH target_url = ( endpoint.with_query(cache_path=cache_path) diff --git a/datalad_registry_client/submit_urls.py b/datalad_registry_client/submit_urls.py index 44870df0..07332c49 100644 --- a/datalad_registry_client/submit_urls.py +++ b/datalad_registry_client/submit_urls.py @@ -1,7 +1,6 @@ import logging from typing import Any, Dict, Iterator, List, Optional -from datalad import cfg from datalad.interface.base import Interface, build_doc, eval_results from datalad.interface.results import get_status_dict from datalad.support.constraints import EnsureNone, EnsureStr @@ -12,6 +11,7 @@ from datalad_registry.blueprints.api import DATASET_URLS_PATH from . import DEFAULT_BASE_ENDPOINT +from .utils import get_base_endpoint lgr = logging.getLogger("datalad.registry.submit_urls") @@ -43,10 +43,9 @@ class RegistrySubmitURLs(Interface): def __call__( urls: List[str], base_endpoint: Optional[str] = None ) -> Iterator[Dict[str, Any]]: + # Set `base_endpoint` based on configuration if it is not provided. if base_endpoint is None: - base_endpoint = cfg.get( - "datalad_registry.base_endpoint", DEFAULT_BASE_ENDPOINT - ) + base_endpoint = get_base_endpoint() endpoint = URL(base_endpoint) / DATASET_URLS_PATH endpoint_str = str(endpoint) diff --git a/datalad_registry_client/utils.py b/datalad_registry_client/utils.py new file mode 100644 index 00000000..2cd7ce2f --- /dev/null +++ b/datalad_registry_client/utils.py @@ -0,0 +1,13 @@ +# This file contains definitions used as tools for the datalad_registry_client package. + +from datalad import cfg + +from . import DEFAULT_BASE_ENDPOINT + + +def get_base_endpoint() -> str: + """ + :return: The value of the `datalad_registry.base_endpoint` option if set, + or the value of `datalad_registry_client.DEFAULT_BASE_ENDPOINT` otherwise. + """ + return cfg.get("datalad_registry.base_endpoint", DEFAULT_BASE_ENDPOINT)