Skip to content

Commit

Permalink
RF: Consolidate code for deciding base endpoint into func
Browse files Browse the repository at this point in the history
  • Loading branch information
candleindark committed Mar 26, 2024
1 parent c2e7077 commit a8dc9ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 3 additions & 5 deletions datalad_registry_client/get_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +15,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.get_urls")

Expand Down Expand Up @@ -64,11 +64,9 @@ 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

Expand Down
7 changes: 3 additions & 4 deletions datalad_registry_client/submit_urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions datalad_registry_client/utils.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a8dc9ce

Please sign in to comment.