From e4ea68f31484dfdad9cce907fb1379b4d9e6ce55 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 16 Jan 2023 18:03:23 +0000 Subject: [PATCH] Allow custom list of domains for inventories Related: https://github.com/mkdocstrings/mkdocstrings/issues/510 --- docs/schema.json | 10 +++++++++- pyproject.toml | 2 +- src/mkdocstrings_handlers/python/handler.py | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/schema.json b/docs/schema.json index a68b9041..0a341cb4 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -26,6 +26,14 @@ "base_url": { "title": "Base URL used to build references URLs.", "type": "string" + }, + "domains": { + "title": "Domains to import from the inventory.", + "description": "If not defined it will only import 'py' domain.", + "type": "array", + "items": { + "type": "string" + } } } } @@ -203,4 +211,4 @@ } }, "additionalProperties": false -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index 914bd58b..1c7e5e0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ classifiers = [ "Typing :: Typed", ] dependencies = [ - "mkdocstrings>=0.19", + "mkdocstrings>=0.20", "griffe>=0.24", ] diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 940f2731..00a4d146 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -168,6 +168,7 @@ def load_inventory( in_file: BinaryIO, url: str, base_url: Optional[str] = None, + domains: list[str] | None = None, **kwargs: Any, ) -> Iterator[Tuple[str, str]]: """Yield items and their URLs from an inventory file streamed from `in_file`. @@ -178,15 +179,17 @@ def load_inventory( in_file: The binary file-like object to read the inventory from. url: The URL that this file is being streamed from (used to guess `base_url`). base_url: The URL that this inventory's sub-paths are relative to. + domains: A list of domain strings to filter the inventory by, when not passed, "py" will be used. **kwargs: Ignore additional arguments passed from the config. Yields: Tuples of (item identifier, item URL). """ + domains = domains or ["py"] if base_url is None: base_url = posixpath.dirname(url) - for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values(): # noqa: WPS526 + for item in Inventory.parse_sphinx(in_file, domain_filter=domains).values(): # noqa: WPS526 yield item.name, posixpath.join(base_url, item.uri) def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102,WPS231