Skip to content

Commit 28b4da2

Browse files
committed
using importlib, fixed but when apidocs is not configured
1 parent b75e75b commit 28b4da2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

changelog.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
* migrated to `mkdocs-material` as part of development
88
* fixed bug in RDF for function parameters
9-
9+
* using `imporlib` approach to find local source module
10+
* fixed bug when apidocs is not configured
1011

1112
## 0.2.0
1213

mkrefs/apidocs.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
You're welcome.
2424
"""
2525

26+
import importlib
2627
import inspect
2728
import os
2829
import re
@@ -74,7 +75,13 @@ def __init__ (
7475
self.git_url = git_url
7576
self.class_list = class_list
7677

77-
self.package_obj = sys.modules[self.package_name]
78+
# hunt for the package
79+
spec = importlib.util.spec_from_file_location(self.package_name, self.package_name + "/__init__.py")
80+
81+
#self.package_obj = sys.modules[self.package_name]
82+
self.package_obj = importlib.util.module_from_spec(spec)
83+
spec.loader.exec_module(self.package_obj) # type: ignore
84+
sys.modules[spec.name] = self.package_obj
7885

7986
# prepare a file path prefix (to remove later, per file)
8087
pkg_path = os.path.dirname(inspect.getfile(self.package_obj))

mkrefs/plugin.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__ (self):
7070
self.enabled = True
7171
self.local_config: dict = defaultdict()
7272

73+
self.apidocs_used = False
7374
self.apidocs_file = None
7475

7576
self.glossary_kg = None
@@ -146,6 +147,9 @@ def on_config ( # pylint: disable=W0613
146147

147148
reuse_graph_path = None
148149

150+
if self._valid_component_config(yaml_path, "apidocs"):
151+
self.apidocs_used = True
152+
149153
if self._valid_component_config(yaml_path, "glossary"):
150154
# load the KG for the glossary
151155
try:
@@ -196,7 +200,7 @@ def on_files ( # pylint: disable=W0613
196200
returns:
197201
the possibly modified global files collection
198202
"""
199-
if self.local_config["apidocs"]["page"]:
203+
if self.apidocs_used and self.local_config["apidocs"]["page"]:
200204
self.apidocs_file = mkdocs.structure.files.File(
201205
path = self.local_config["apidocs"]["page"],
202206
src_dir = config["docs_dir"],

0 commit comments

Comments
 (0)