@@ -99,6 +99,8 @@ class PythonHandler(BaseHandler):
99
99
"members" : None ,
100
100
"filters" : ["!^_[^_]" ],
101
101
"annotations_path" : "brief" ,
102
+ "preload_modules" : None ,
103
+ "load_external_modules" : False ,
102
104
}
103
105
"""
104
106
Attributes: Headings options:
@@ -150,6 +152,16 @@ class PythonHandler(BaseHandler):
150
152
Attributes: Additional options:
151
153
show_bases (bool): Show the base classes of a class. Default: `True`.
152
154
show_source (bool): Show the source code of this object. Default: `True`.
155
+ preload_modules (list[str] | None): Pre-load modules that are
156
+ not specified directly in autodoc instructions (`::: identifier`).
157
+ It is useful when you want to render documentation for a particular member of an object,
158
+ and this member is imported from another package than its parent.
159
+
160
+ For an imported member to be rendered, you need to add it to the `__all__` attribute
161
+ of the importing module.
162
+
163
+ The modules must be listed as an array of strings. Default: `None`.
164
+
153
165
""" # noqa: E501
154
166
155
167
def __init__ (
@@ -235,12 +247,16 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
235
247
modules_collection = self ._modules_collection ,
236
248
lines_collection = self ._lines_collection ,
237
249
)
238
- try :
250
+ try : # noqa: WPS229 we expect one type of exception, and want to fail on the first one
251
+ for pre_loaded_module in final_config .get ("preload_modules" ) or []:
252
+ if pre_loaded_module not in self ._modules_collection :
253
+ loader .load_module (pre_loaded_module )
239
254
loader .load_module (module_name )
240
255
except ImportError as error :
241
256
raise CollectionError (str (error )) from error
242
-
243
- unresolved , iterations = loader .resolve_aliases (implicit = False , external = False )
257
+ unresolved , iterations = loader .resolve_aliases (
258
+ implicit = False , external = final_config ["load_external_modules" ]
259
+ )
244
260
if unresolved :
245
261
logger .debug (f"{ len (unresolved )} aliases were still unresolved after { iterations } iterations" )
246
262
logger .debug (f"Unresolved aliases: { ', ' .join (sorted (unresolved ))} " )
0 commit comments