Skip to content

Commit a8618d0

Browse files
committed
codemeta: Workaround pyld issue for compact operation
pyld is not correctly loading json-ld content from http*://schema.org (see digitalbazaar/pyld#154) and raises an exception when attempting to compact a codemeta document having schema.org in its @context list. As a workaround, remove schema.org from the @context list of a codemeta document before compacting it.
1 parent e42deb6 commit a8618d0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

swh/indexer/codemeta.py

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def compact(doc, forgefed: bool):
146146
This is typically used for extrinsic metadata documents, which frequently
147147
use properties from these namespaces.
148148
"""
149+
if "@context" in doc and isinstance(doc["@context"], list):
150+
# workaround pyld issue (https://github.com/digitalbazaar/pyld/issues/154)
151+
doc["@context"] = [
152+
context
153+
for context in doc["@context"]
154+
if not context.endswith("/schema.org")
155+
]
149156
contexts: List[Any] = [CODEMETA_CONTEXT_URL]
150157
if forgefed:
151158
contexts.append(

swh/indexer/tests/test_bibtex.py

+28
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,34 @@ def test_invalid_date():
299299
)
300300

301301

302+
def test_context_contains_schema_org():
303+
assert codemeta_to_bibtex(
304+
{
305+
"@context": [
306+
"https://doi.org/10.5063/schema/codemeta-2.0",
307+
"http://schema.org",
308+
],
309+
"author": {"name": "Jane Doe"},
310+
"name": "Example Software",
311+
"url": "http://example.org/",
312+
"datePublished": "2023-10-10",
313+
"license": "https://spdx.org/licenses/Apache-2.0",
314+
}
315+
) == textwrap.dedent(
316+
"""\
317+
@software{REPLACEME,
318+
author = "Doe, Jane",
319+
license = "Apache-2.0",
320+
date = "2023-10-10",
321+
year = "2023",
322+
month = oct,
323+
title = "Example Software",
324+
url = "http://example.org/"
325+
}
326+
"""
327+
)
328+
329+
302330
def test_cff_empty():
303331
assert cff_to_bibtex("") == textwrap.dedent(
304332
"""\

0 commit comments

Comments
 (0)