Skip to content

Commit 00d6f90

Browse files
Lazy import for docs (#936)
Introduce lazy loading of submodules and so that mkdocs does not fail. --------- Co-authored-by: Jesper Friis <jesper.friis@sintef.no> Co-authored-by: Jesper Friis <jesper-friis@users.noreply.github.com>
1 parent 94a8c77 commit 00d6f90

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

.github/workflows/ci_cd_updated_master.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: CI/CD - New updates to 'master'
22

33
on:
44
push:
5-
branches: [master]
5+
branches:
6+
- master
7+
- lazy_import_for_docs
68

79
jobs:
810
updates-to-master:
@@ -23,7 +25,7 @@ jobs:
2325
emmopy
2426
ontopy
2527
python_version: "3.13"
26-
doc_extras: "[docs,excel,ontodoc]"
28+
doc_extras: "[docs,excel,ontodoc,ontokit]"
2729
special_file_api_ref_options: "emmopy/emmocheck.py,show_bases: false"
2830
landing_page_replacements: |
2931
(LICENSE.txt),(LICENSE.md)

ontopy/ontokit/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
"""Ontopy subpackage for creating workflows and documenting ontologies"""
1+
"""Ontopy subpackage for creating workflows and documenting ontologies."""
2+
3+
from importlib import import_module
4+
5+
__all__ = ["docs", "setup"]
6+
7+
8+
def __getattr__(name):
9+
"""Lazily expose submodules for tooling such as mkdocstrings.
10+
11+
It will import the `docs` module when a user does
12+
`import ontokit.docs`. Similar for the other modules.
13+
"""
14+
if name in __all__:
15+
module = import_module(f"{__name__}.{name}")
16+
globals()[name] = module
17+
return module
18+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)