Skip to content

Commit b2baad1

Browse files
authored
Merge pull request #531 from bioimage-io/fix_root_path
Fix root path issue related to new zenodo api
2 parents 03183a1 + 2a9aba2 commit b2baad1

File tree

6 files changed

+12
-33
lines changed

6 files changed

+12
-33
lines changed

bioimageio/spec/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.4.9post3"
2+
"version": "0.4.9post4"
33
}

bioimageio/spec/shared/_resolve_source.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ def resolve_rdf_source(
106106
# source is bioimageio id or bioimageio nickname
107107
source = bioimageio_rdf_source
108108
elif re.fullmatch(DOI_REGEX, source): # turn doi into url
109-
import requests # not available in pyodide
110-
111109
zenodo_prefix = "10.5281/zenodo."
112110
zenodo_record_api = "https://zenodo.org/api/records"
113111
zenodo_sandbox_prefix = "10.5072/zenodo."
@@ -136,23 +134,7 @@ def resolve_rdf_source(
136134

137135
record_id = record_id.split("/")[-1]
138136

139-
response = requests.get(f"{zenodo_record_api}/{record_id}")
140-
if not response.ok:
141-
raise RuntimeError(response.status_code)
142-
143-
zenodo_record = response.json()
144-
for rdf_name in RDF_NAMES:
145-
for f in zenodo_record["files"]:
146-
if f["key"] == rdf_name:
147-
source = f["links"]["self"]
148-
break
149-
else:
150-
continue
151-
152-
break
153-
else:
154-
raise ValidationError(f"No RDF found; looked for {RDF_NAMES}")
155-
137+
source = f"{zenodo_record_api}/{record_id}/files/rdf.yaml/content"
156138
else:
157139
# resolve doi
158140
# todo: make sure the resolved url points to a rdf.yaml or a zipped package

bioimageio/spec/shared/raw_nodes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ def __truediv__(self, other):
8787

8888
@property
8989
def parent(self):
90-
path_parent = pathlib.PurePosixPath(self.path).parent.as_posix()
91-
return dataclasses.replace(self, path=path_parent, uri_string=None)
90+
path = pathlib.PurePosixPath(self.path)
91+
if self.authority == "zenodo.org" and self.path.startswith("/api/records/") and self.path.endswith("/content"):
92+
parent_path = (path.parent.parent / "content").as_posix()
93+
else:
94+
parent_path = path.parent.as_posix()
95+
96+
return dataclasses.replace(self, path=parent_path, uri_string=None)
9297

9398
def __post_init__(self):
9499
uri_string = self.uri_string # should be InitVar, see comment at definition above

tests/test_commands.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from bioimageio.spec.model import format_version, raw_nodes
1212
from bioimageio.spec.shared import yaml
1313

14-
SKIP_ZENODO = True
14+
SKIP_ZENODO = False
1515
SKIP_ZENODO_REASON = "zenodo api changes"
1616

1717

@@ -46,14 +46,6 @@ def test_validate_model_as_url():
4646
)["error"]
4747

4848

49-
@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
50-
def test_validate_model_as_zenodo_sandbox_doi():
51-
from bioimageio.spec.commands import validate
52-
53-
doi = "10.5281/zenodo.5744489"
54-
assert not validate(doi, update_format=False, update_format_inner=False)["error"]
55-
56-
5749
@pytest.mark.skipif(SKIP_ZENODO, reason=SKIP_ZENODO_REASON)
5850
def test_validate_model_as_zenodo_doi():
5951
from bioimageio.spec.commands import validate

tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from bioimageio.spec.shared import yaml
66

7-
SKIP_ZENODO = True
7+
SKIP_ZENODO = False
88
SKIP_ZENODO_REASON = "zenodo api changes"
99

1010

tests/test_schema_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from bioimageio.spec.model.v0_4 import raw_nodes as raw_nodes_m04
77
from bioimageio.spec.shared import yaml
88

9-
SKIP_ZENODO = True
9+
SKIP_ZENODO = False
1010
SKIP_ZENODO_REASON = "zenodo api changes"
1111

1212

0 commit comments

Comments
 (0)