Skip to content

Commit

Permalink
Add --with-dataset-types to kart meta get
Browse files Browse the repository at this point in the history
Simply adds two fields to each datasets output:
"datasetType" and "version".

Most existing datasets will be ("table", 3).
Experimental point cloud datasets are ("point-cloud", 1)
  • Loading branch information
olsen232 committed Jun 10, 2022
1 parent ec3e010 commit 8a25ba1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
13 changes: 12 additions & 1 deletion kart/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ def meta(ctx, **kwargs):
help="[deprecated] How to format the JSON output. Only used with -o json",
)
@click.option("--ref", default="HEAD")
@click.option(
"--with-dataset-types",
is_flag=True,
help="When set, includes the dataset type and version as pseudo meta-items (these cannot be updated).",
)
@click.argument("dataset", required=False)
@click.argument("keys", required=False, nargs=-1)
@click.pass_context
def meta_get(ctx, output_format, json_style, ref, dataset, keys):
def meta_get(ctx, output_format, json_style, ref, with_dataset_types, dataset, keys):
"""
Prints the value of meta keys.
Expand All @@ -80,6 +85,12 @@ def meta_get(ctx, output_format, json_style, ref, dataset, keys):
all_items[ds.path] = get_meta_items(ds, keys)
else:
all_items[ds.path] = ds.meta_items()
if with_dataset_types:
all_items[ds.path] = {
"datasetType": ds.DATASET_TYPE,
"version": ds.VERSION,
**all_items[ds.path],
}

output_type, fmt = parse_output_format(output_format, json_style)

Expand Down
35 changes: 32 additions & 3 deletions tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ def test_errors(self, data_archive_readonly, cli_runner):

@pytest.mark.parametrize("output_format", ("text", "json"))
def test_all(self, output_format, data_archive_readonly, cli_runner):
# All datasets now support getting metadata in either V1 or V2 format,
# but if you don't specify a particular item, they will show all V2 items -
# these are more self-explanatory to an end-user.
with data_archive_readonly("points"):
r = cli_runner.invoke(
["meta", "get", "nz_pa_points_topo_150k", "-o", output_format]
Expand All @@ -44,6 +41,38 @@ def test_all(self, output_format, data_archive_readonly, cli_runner):
assert output["schema.json"]
assert output["crs/EPSG:4326.wkt"]

@pytest.mark.parametrize("output_format", ("text", "json"))
def test_with_dataset_types(self, output_format, data_archive_readonly, cli_runner):
with data_archive_readonly("points"):
r = cli_runner.invoke(
[
"meta",
"get",
"nz_pa_points_topo_150k",
"--with-dataset-types",
"-o",
output_format,
]
)
assert r.exit_code == 0, r
if output_format == "text":
assert "datasetType" in r.stdout
assert "version" in r.stdout
assert "title" in r.stdout
assert EXPECTED_TITLE in r.stdout
assert "description" in r.stdout
assert "schema.json" in r.stdout
assert "crs/EPSG:4326.wkt" in r.stdout
else:
output = json.loads(r.stdout)
output = output["nz_pa_points_topo_150k"]
assert output["datasetType"] == "table"
assert output["version"] == 3
assert output["title"] == EXPECTED_TITLE
assert output["description"]
assert output["schema.json"]
assert output["crs/EPSG:4326.wkt"]

@pytest.mark.parametrize("output_format", ("text", "json"))
def test_keys(self, output_format, data_archive_readonly, cli_runner):
with data_archive_readonly("points"):
Expand Down

0 comments on commit 8a25ba1

Please sign in to comment.