Skip to content

Commit 7dc5474

Browse files
committed
fix(onto2py): skip imports without generated python module
Skip http(s) imports that have no generated python module (no abi:pythonPackage + abi:pythonResource annotations) to avoid import errors for upper ontologies like bfo-core.ttl.
1 parent d91b644 commit 7dc5474

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • libs/naas-abi-core/naas_abi_core/utils/onto2py

libs/naas-abi-core/naas_abi_core/utils/onto2py/onto2py.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,10 +1183,20 @@ def _resolve_owl_import(
11831183
ttl_path = _materialize_locator_ttl(locator)
11841184
if ttl_path is None:
11851185
return None
1186+
# An ``http(s)`` import is only usable for codegen when the imported
1187+
# ontology declares where its generated module lives
1188+
# (``abi:pythonPackage`` + ``abi:pythonResource``). Upper ontologies
1189+
# like ``bfo-core.ttl`` carry no such annotations and have no generated
1190+
# ``.py`` (they also live under hyphenated, non-importable directories
1191+
# such as ``imports/top-level/``). Falling back to a path-derived module
1192+
# would emit ``from naas_abi.ontologies.imports import ...`` against a
1193+
# module that does not exist. Skip with a warning instead; the BFO
1194+
# parents are then handled like any other unresolved import (subclasses
1195+
# fall back to RDFEntity), keeping the generated module self-contained.
1196+
py_module = _python_module_for_locator(locator)
1197+
if py_module is None:
1198+
return None
11861199
content = ttl_path.read_text()
1187-
py_module = _python_module_for_locator(locator) or _path_to_python_module(
1188-
ttl_path
1189-
)
11901200
return content, py_module
11911201

11921202
if iri.startswith(_FILE_IMPORT_SCHEME):

0 commit comments

Comments
 (0)