Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix inventory base_url handling #269

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

Merged
merged 1 commit into from
Apr 3, 2025
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
4 changes: 2 additions & 2 deletions 4 src/mkdocstrings_handlers/python/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ class Inventory:
),
]

base: Annotated[
base_url: Annotated[
str | None,
_Field(
parent="inventories",
Expand All @@ -989,7 +989,7 @@ class Inventory:

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


# YORE: EOL 3.9: Replace `**_dataclass_options` with `frozen=True, kw_only=True` within line.
Expand Down
35 changes: 34 additions & 1 deletion 35 tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

import os
import sys
from dataclasses import replace
from glob import glob
from io import BytesIO
from pathlib import Path
from textwrap import dedent
from typing import TYPE_CHECKING

import mkdocstrings
import pytest
from griffe import (
Docstring,
Expand All @@ -20,7 +23,7 @@
)
from mkdocstrings import CollectionError

from mkdocstrings_handlers.python import PythonConfig, PythonHandler, PythonOptions
from mkdocstrings_handlers.python import Inventory, PythonConfig, PythonHandler, PythonOptions

if TYPE_CHECKING:
from mkdocstrings import MkdocstringsPlugin
Expand Down Expand Up @@ -298,3 +301,33 @@ class B(A): ...
module,
handler.get_options({"inherited_members": True}),
)


def test_specifying_inventory_base_url(handler: PythonHandler) -> None:
"""Assert that the handler renders inventory URLs using the specified base_url."""
# Update handler config to include an inventory with a base URL
base_url = "https://docs.com/my_library"
inventory = Inventory(url="https://example.com/objects.inv", base_url=base_url)
handler.config = replace(handler.config, inventories=[inventory])

# Mock inventory bytes
item_name = "my_library.my_module.MyClass"
mocked_inventory = mkdocstrings.Inventory()
mocked_inventory.register(
name=item_name,
domain="py",
role="class",
uri=f"api-reference/#{item_name}",
dispname=item_name,
)
mocked_bytes = BytesIO(mocked_inventory.format_sphinx())

# Get inventory URL and config
url, config = handler.get_inventory_urls()[0]

# Load the mocked inventory
_, item_url = next(handler.load_inventory(mocked_bytes, url, **config))

# Assert the URL is based on the provided base URL
msg = "Expected inventory URL to start with base_url"
assert item_url.startswith(base_url), msg
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.