Skip to content

Commit

Permalink
TMP: Give meta-dump basic parameter constraints from next
Browse files Browse the repository at this point in the history
This adds an 'EnsureDataset()' parameter validation, and an 'EnsureStr()'
parameter validation for the path argument.
The immediate advantage is that there are now distinct errors for
NoMetaDataStoreFound and NoDatasetFound, which were prior both resulting
in a NoMetaDataStoreFound exception.
  • Loading branch information
adswa committed Mar 2, 2023
1 parent fa89539 commit 22f1077
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions datalad_metalad/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@

from datalad.distribution.dataset import datasetmethod
from datalad.interface.base import (
Interface,
build_doc,
eval_results,
)
from datalad.support.constraints import (
EnsureNone,
from datalad_next.commands import (
EnsureCommandParameterization,
ValidatedInterface,
)
from datalad_next.constraints import (
EnsureStr,
EnsureNone,
)
from datalad_next.constraints.dataset import EnsureDataset
from datalad.support.param import Parameter
from datalad.ui import ui
from dataladmetadatamodel.datasettree import datalad_root_record_name
Expand Down Expand Up @@ -413,7 +417,7 @@ def dump_from_uuid_set(mapper: str,


@build_doc
class Dump(Interface):
class Dump(ValidatedInterface):
"""Dump a dataset's aggregated metadata for dataset and file metadata
Two types of metadata are supported:
Expand All @@ -432,6 +436,16 @@ class Dump(Interface):
(The tree-format is the default format and does not require a prefix).
"""

# Define parameter constraints
_validator_ = EnsureCommandParameterization(
param_constraints=dict(
dataset=EnsureDataset(installed=True, purpose='meta-dump'),
path=EnsureStr(),
),
validate_defaults=("dataset",)
)


# Use a custom renderer to emit a self-contained metadata record. The
# emitted record can be fed into meta-add for example.
result_renderer = 'tailored'
Expand Down Expand Up @@ -481,7 +495,6 @@ class Dump(Interface):
args=("path",),
metavar="DATASET_FILE_PATH_PATTERN",
doc="path to query metadata for",
constraints=EnsureStr() | EnsureNone(),
nargs="?"),
recursive=Parameter(
args=("-r", "--recursive",),
Expand All @@ -501,6 +514,8 @@ def __call__(
path="",
recursive=False):

# dataset is a DatasetParameter() from datalad-next
dataset = dataset.ds.path
metadata_store_path, tree_version_list, uuid_set = get_metadata_objects(
dataset,
default_mapper_family)
Expand Down

0 comments on commit 22f1077

Please sign in to comment.