Skip to content

Commit 2176c16

Browse files
committed
chore(deps): bump pyld version to 3.0.0 and update usage
1 parent 867c046 commit 2176c16

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies = [
1616
"pydantic>=2.9.2",
1717
"sqlalchemy>=2.0.36",
1818
"sqlmodel>=0.0.22",
19-
"pyld>=2.0.4",
19+
"pyld>=3.0.0",
2020
"requests>=2.32.3",
2121
"toml>=0.10.2",
2222
"typer>=0.15.0",

src/esgvoc/core/data_handler.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def unified_document_loader(uri: str) -> Dict:
2121
_LOGGER.error(f"Failed to fetch remote document: {response.status_code} - {response.text}")
2222
return {}
2323
else:
24+
# Handle file:// URIs by converting to local path
25+
if uri.startswith("file://"):
26+
from urllib.parse import unquote, urlparse
27+
uri = unquote(urlparse(uri).path)
2428
with open(uri, "r") as f:
2529
return json.load(f)
2630

@@ -144,7 +148,12 @@ def expanded(self) -> Any:
144148
preprocessed["@context"] = data["@context"]
145149

146150
# Expand the preprocessed data
147-
return jsonld.expand(preprocessed, options={"base": self.uri})
151+
# Convert file paths to file:// URIs for pyld 3.0+ compatibility
152+
base_uri = self.uri
153+
if not base_uri.startswith(("http://", "https://", "file://")):
154+
from pathlib import Path
155+
base_uri = Path(base_uri).as_uri()
156+
return jsonld.expand(preprocessed, options={"base": base_uri})
148157

149158
@cached_property
150159
def context(self) -> Dict:
@@ -170,7 +179,12 @@ def context(self) -> Dict:
170179
def normalized(self) -> str:
171180
"""Normalize the JSON-LD data."""
172181
_LOGGER.info(f"Normalizing JSON-LD data for {self.uri}")
173-
return jsonld.normalize(self.uri, options={"algorithm": "URDNA2015", "format": "application/n-quads"})
182+
# Convert file paths to file:// URIs for pyld 3.0+ compatibility
183+
uri = self.uri
184+
if not uri.startswith(("http://", "https://", "file://")):
185+
from pathlib import Path
186+
uri = Path(uri).as_uri()
187+
return jsonld.normalize(uri, options={"algorithm": "URDNA2015", "format": "application/n-quads"})
174188

175189
def _extract_model_key(self, uri: str) -> Optional[str]:
176190
"""Extract a model key from the URI."""

0 commit comments

Comments
 (0)