Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
"enum": ["brief", "source"],
"default": "brief"
},
"preload_modules": {
"title": "Pre-load modules. It permits to resolve aliases pointing to these modules (packages), and therefore render members of an object that are external to the given object (originating from another package).",
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",
"type": "array",
"items": {
"type":"string"
}
}
},
"additionalProperties": false
Expand Down
16 changes: 15 additions & 1 deletion src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class PythonHandler(BaseHandler):
"members": None,
"filters": ["!^_[^_]"],
"annotations_path": "brief",
"preload_modules": None,
}
"""
Attributes: Headings options:
Expand Down Expand Up @@ -150,6 +151,16 @@ class PythonHandler(BaseHandler):
Attributes: Additional options:
show_bases (bool): Show the base classes of a class. Default: `True`.
show_source (bool): Show the source code of this object. Default: `True`.
preload_modules (list[str] | None): Pre-load modules that are
not specified directly in autodoc instructions (`::: identifier`).
It is useful when you want to render documentation for a particular member of an object,
and this member is imported from another package than its parent.

For an imported member to be rendered, you need to add it to the `__all__` attribute
of the importing module.

The modules must be listed as an array of strings. Default: `None`.

""" # noqa: E501

def __init__(
Expand Down Expand Up @@ -235,7 +246,10 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
modules_collection=self._modules_collection,
lines_collection=self._lines_collection,
)
try:
try: # noqa: WPS229 we expect one type of exception, and want to fail on the first one
for pre_loaded_module in final_config.get("preload_modules") or []:
if pre_loaded_module not in self._modules_collection:
loader.load_module(pre_loaded_module)
loader.load_module(module_name)
except ImportError as error:
raise CollectionError(str(error)) from error
Expand Down