Skip to content

Commit

Permalink
codemeta: Workaround pyld issue for compact operation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
anlambert committed Nov 8, 2024
1 parent e42deb6 commit a8618d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions swh/indexer/codemeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def compact(doc, forgefed: bool):
This is typically used for extrinsic metadata documents, which frequently
use properties from these namespaces.
"""
if "@context" in doc and isinstance(doc["@context"], list):
# workaround pyld issue (https://github.com/digitalbazaar/pyld/issues/154)
doc["@context"] = [
context
for context in doc["@context"]
if not context.endswith("/schema.org")
]
contexts: List[Any] = [CODEMETA_CONTEXT_URL]
if forgefed:
contexts.append(
Expand Down
28 changes: 28 additions & 0 deletions swh/indexer/tests/test_bibtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,34 @@ def test_invalid_date():
)


def test_context_contains_schema_org():
assert codemeta_to_bibtex(
{
"@context": [
"https://doi.org/10.5063/schema/codemeta-2.0",
"http://schema.org",
],
"author": {"name": "Jane Doe"},
"name": "Example Software",
"url": "http://example.org/",
"datePublished": "2023-10-10",
"license": "https://spdx.org/licenses/Apache-2.0",
}
) == textwrap.dedent(
"""\
@software{REPLACEME,
author = "Doe, Jane",
license = "Apache-2.0",
date = "2023-10-10",
year = "2023",
month = oct,
title = "Example Software",
url = "http://example.org/"
}
"""
)


def test_cff_empty():
assert cff_to_bibtex("") == textwrap.dedent(
"""\
Expand Down

0 comments on commit a8618d0

Please sign in to comment.