Skip to content

Commit

Permalink
Merge pull request #413 from datalad/handbook
Browse files Browse the repository at this point in the history
Fix config-related issues picked up in handbook tutorial
  • Loading branch information
jsheunis authored Jan 17, 2024
2 parents 45a7a8b + b558013 commit c5312fd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 104 deletions.
7 changes: 7 additions & 0 deletions datalad_catalog/catalog/assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ var datacat = new Vue({
})
.then((responseJson) => {
obj = responseJson;
// first ensure that the config has all required fields;
// if some are missing, fill them in from default_config
for (const [key, value] of Object.entries(default_config)) {
if (!obj.hasOwnProperty(key) ) {
obj[key] = value;
}
}
// set social links
this.social_links = obj.social_links
// set dataset options
Expand Down
32 changes: 6 additions & 26 deletions datalad_catalog/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,16 @@
},
"property_sources": {
"dataset": {
"dataset_id": {
"rule": "single",
"source": "metalad_core"
},
"dataset_version": {
"rule": "single",
"source": "metalad_core"
},
"type": {
"rule": "single",
"source": "metalad_core"
},
"dataset_id": {},
"dataset_version": {},
"type": {},
"children": {
"rule": "merge",
"source": "any"
},
"name": {
"rule": "single",
"source": "metalad_studyminimeta"
},
"name": {},
"short_name": {},
"description": {
"rule": "priority",
"source": [
"catalog_readme",
"metalad_studyminimeta",
"datacite_gin",
"bids_dataset"
]
},
"description": {},
"doi": {},
"url": {
"rule": "merge",
Expand Down Expand Up @@ -80,5 +60,5 @@
"source": "any"
}
}
}
}
}
69 changes: 0 additions & 69 deletions datalad_catalog/config/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion datalad_catalog/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def __call__(
# Dataset-level will inherit from catalog config in any case.
if metadata is not None:
catalog_add = Add()
yield from catalog_add(
yield catalog_add(
catalog=catalog,
metadata=metadata,
config_file=None,
Expand Down
3 changes: 2 additions & 1 deletion datalad_catalog/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
from datalad_catalog.constants import (
package_path,
default_config_dir,
tests_path,
)
from datalad_catalog.webcatalog import WebCatalog
Expand All @@ -11,7 +12,7 @@ class TestPaths(object):
"""Class to store paths to test data"""

data_path = tests_path / "data"
default_config_path = package_path / "config" / "config.json"
default_config_path = default_config_dir / "config.json"
demo_config_path_catalog = data_path / "test_config_file_catalog.json"
demo_config_path_dataset = data_path / "test_config_file_dataset.json"
catalog_metadata_dataset1 = (
Expand Down
17 changes: 11 additions & 6 deletions datalad_catalog/tests/test_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from datalad_catalog.create import Create
from datalad_catalog.utils import read_json_file
from datalad.tests.utils_pytest import (
assert_in_results,
)
Expand Down Expand Up @@ -53,9 +54,10 @@ def test_create_with_metadata(tmp_path, test_data):
does not yet exist and some metadata as the input args
"""
catalog_path = tmp_path / "test_catalog"
mdata_path = test_data.catalog_metadata_dataset1
res = catalog_create(
catalog=catalog_path,
metadata=test_data.catalog_metadata_dataset1,
metadata=mdata_path,
)
assert_in_results(
res,
Expand All @@ -68,12 +70,15 @@ def test_create_with_metadata(tmp_path, test_data):
for p in catalog_paths:
pth = catalog_path / p
assert pth.exists()
assert_in_results(
res,
action="catalog_add",
status="ok",
path=catalog_path,
mdata = read_json_file(mdata_path)
ds_mdata_dir = (
catalog_path
/ "metadata"
/ mdata.get("dataset_id")
/ mdata.get("dataset_version")
)
assert ds_mdata_dir.exists()
assert ds_mdata_dir.is_dir()


def test_create_at_existing_noncatalog(tmp_path):
Expand Down
2 changes: 1 addition & 1 deletion datalad_catalog/webcatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def get_logo_path(self):
def get_config(self):
""""""
# Read config from file
config_path = cnst.default_config_dir / "config.json"
config_path = self.location / "config.json"
if not config_path.exists():
return None
return load_config_file(config_path)
Expand Down

0 comments on commit c5312fd

Please sign in to comment.