Skip to content

Commit

Permalink
Merge pull request #348 from candleindark/refactor-clients
Browse files Browse the repository at this point in the history
RF: Refactor client
  • Loading branch information
candleindark authored Mar 26, 2024
2 parents 6fca897 + a8dc9ce commit 55e067e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
16 changes: 6 additions & 10 deletions datalad_registry_client/get_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
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
from datalad.support.param import Parameter
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")

Expand Down Expand Up @@ -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)
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 55e067e

Please sign in to comment.