Skip to content

Commit

Permalink
feat: Allow custom list of domains for inventories
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 23, 2023
1 parent 32be783 commit f5ea6fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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 @@ -169,6 +169,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 @@ -179,15 +180,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: Mapping[str, Any]) -> CollectorItem: # noqa: D102,WPS231
Expand Down

0 comments on commit f5ea6fd

Please sign in to comment.