Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pipeline/src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from .base import Link


DEFAULT_VERSION = "v4"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of using a constant here, it would be better to automatically select the latest version, excluding "latest" itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that would be better. I propose to leave this for a future pull request.



class Collection:
"""
A collection of metadata nodes that can be saved to
Expand Down Expand Up @@ -141,7 +144,7 @@ def save(self, path, individual_files=False, include_empty_properties=False):
output_paths.append(file_path)
return output_paths

def load(self, *paths):
def load(self, *paths, version=DEFAULT_VERSION):
"""
Load openMINDS metadata from one or more JSON-LD files.

Expand All @@ -152,6 +155,9 @@ def load(self, *paths):
(but without descending into subdirectories)

2) one or more JSON-LD files, which will all be loaded.

By default, openMINDS v4 will be used.
If the JSON-LD files use a different openMINDS version, specify it with the `version` argument.
"""
if len(paths) == 1 and os.path.isdir(paths[0]):
data_dir = paths[0]
Expand All @@ -168,10 +174,6 @@ def load(self, *paths):
with open(path, "r") as fp:
data = json.load(fp)
if "@graph" in data:
if data["@context"]["@vocab"].startswith("https://openminds.ebrains.eu/"):
version = "v3"
else:
version = "latest"
for item in data["@graph"]:
if "@type" in item:
cls = lookup_type(item["@type"], version=version)
Expand Down Expand Up @@ -245,4 +247,3 @@ def sort_nodes_for_upload(self):
newly_sorted.append(node_id)
unsorted -= set(newly_sorted)
return [self.nodes[node_id] for node_id in sorted]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty line seems to be missing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I don't think so. I think it's just that GitHub doesn't show a line if the file ends with a linebreak

8 changes: 4 additions & 4 deletions pipeline/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
from openminds import Collection, IRI
from openminds.latest import core as omcore
from openminds.v4 import core as omcore
from utils import build_fake_node


Expand Down Expand Up @@ -261,12 +261,12 @@ def test_issue0073():
# Infinite recursion in validate()
ds1 = omcore.DatasetVersion(
short_name="ds1",
is_variant_of=None
is_alternative_version_of=None
)
ds2 = omcore.DatasetVersion(
short_name="ds2",
is_variant_of=ds1
is_alternative_version_of=ds1
)
ds1.is_variant_of = ds2
ds1.is_alternative_version_of = ds2

failures = ds1.validate()