Skip to content

Commit 02052e2

Browse files
authored
feat: Allow resolving alias to external modules
PR #61: #61 Follow-up of PR #60: #60 Co-authored-by: gilfree <[email protected]>
1 parent 36002cb commit 02052e2

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

docs/schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
"format": "path"
5050
}
5151
},
52+
"load_external_modules": {
53+
"title": "Load external modules to resolve aliases.",
54+
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#global-only-options",
55+
"type": "boolean",
56+
"default": false
57+
},
5258
"options": {
5359
"title": "Options for collecting and rendering objects.",
5460
"markdownDescription": "https://mkdocstrings.github.io/python/usage/#globallocal-options",

docs/usage.md

+9
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ Some options are **global only**, and go directly under the handler's name.
5252

5353
More details at [Finding modules](#finding-modules).
5454

55+
- `load_external_modules`:
56+
this option allows resolving aliases to any external module.
57+
Enabling this option will tell handler that when it encounters an import that is made public
58+
through the `__all__` variable, it will resolve it recursively to *any* module.
59+
**Use with caution:** this can load a *lot* of modules, slowing down your build
60+
or triggering errors that we do not yet handle.
61+
**We recommend using the `preload_modules` option instead**,
62+
which acts as an include-list rather than as include-all.
63+
5564
## Global/local options
5665

5766
The other options can be used both globally *and* locally, under the `options` key.

src/mkdocstrings_handlers/python/handler.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class PythonHandler(BaseHandler):
100100
"filters": ["!^_[^_]"],
101101
"annotations_path": "brief",
102102
"preload_modules": None,
103+
"load_external_modules": False,
103104
}
104105
"""
105106
Attributes: Headings options:
@@ -253,8 +254,9 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
253254
loader.load_module(module_name)
254255
except ImportError as error:
255256
raise CollectionError(str(error)) from error
256-
257-
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+
)
258260
if unresolved:
259261
logger.debug(f"{len(unresolved)} aliases were still unresolved after {iterations} iterations")
260262
logger.debug(f"Unresolved aliases: {', '.join(sorted(unresolved))}")

0 commit comments

Comments
 (0)