Skip to content

Commit 8870eb9

Browse files
authored
fix: Fix inventory base_url being ignored
Issue-268: #268 PR-269: #269
1 parent 6d16798 commit 8870eb9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/mkdocstrings_handlers/python/_internal/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ class Inventory:
971971
),
972972
]
973973

974-
base: Annotated[
974+
base_url: Annotated[
975975
str | None,
976976
_Field(
977977
parent="inventories",
@@ -989,7 +989,7 @@ class Inventory:
989989

990990
@property
991991
def _config(self) -> dict[str, Any]:
992-
return {"base": self.base, "domains": self.domains}
992+
return {"base_url": self.base_url, "domains": self.domains}
993993

994994

995995
# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.

tests/test_handler.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
import os
66
import sys
7+
from dataclasses import replace
78
from glob import glob
9+
from io import BytesIO
810
from pathlib import Path
911
from textwrap import dedent
1012
from typing import TYPE_CHECKING
1113

14+
import mkdocstrings
1215
import pytest
1316
from griffe import (
1417
Docstring,
@@ -20,7 +23,7 @@
2023
)
2124
from mkdocstrings import CollectionError
2225

23-
from mkdocstrings_handlers.python import PythonConfig, PythonHandler, PythonOptions
26+
from mkdocstrings_handlers.python import Inventory, PythonConfig, PythonHandler, PythonOptions
2427

2528
if TYPE_CHECKING:
2629
from mkdocstrings import MkdocstringsPlugin
@@ -298,3 +301,33 @@ class B(A): ...
298301
module,
299302
handler.get_options({"inherited_members": True}),
300303
)
304+
305+
306+
def test_specifying_inventory_base_url(handler: PythonHandler) -> None:
307+
"""Assert that the handler renders inventory URLs using the specified base_url."""
308+
# Update handler config to include an inventory with a base URL
309+
base_url = "https://docs.com/my_library"
310+
inventory = Inventory(url="https://example.com/objects.inv", base_url=base_url)
311+
handler.config = replace(handler.config, inventories=[inventory])
312+
313+
# Mock inventory bytes
314+
item_name = "my_library.my_module.MyClass"
315+
mocked_inventory = mkdocstrings.Inventory()
316+
mocked_inventory.register(
317+
name=item_name,
318+
domain="py",
319+
role="class",
320+
uri=f"api-reference/#{item_name}",
321+
dispname=item_name,
322+
)
323+
mocked_bytes = BytesIO(mocked_inventory.format_sphinx())
324+
325+
# Get inventory URL and config
326+
url, config = handler.get_inventory_urls()[0]
327+
328+
# Load the mocked inventory
329+
_, item_url = next(handler.load_inventory(mocked_bytes, url, **config))
330+
331+
# Assert the URL is based on the provided base URL
332+
msg = "Expected inventory URL to start with base_url"
333+
assert item_url.startswith(base_url), msg

0 commit comments

Comments
 (0)