Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom list of domains for inventories #49

Merged
merged 1 commit into from
Jan 23, 2023
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
10 changes: 9 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
Expand Down Expand Up @@ -203,4 +211,4 @@
}
},
"additionalProperties": false
}
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ classifiers = [
"Typing :: Typed",
]
dependencies = [
"mkdocstrings>=0.19",
"mkdocstrings>=0.20",
"griffe>=0.24",
]

Expand Down
5 changes: 4 additions & 1 deletion src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand Down