diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd5c263..8798a05a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.16.10](https://github.com/mkdocstrings/python/releases/tag/1.16.10) - 2025-04-03 + +[Compare with 1.16.9](https://github.com/mkdocstrings/python/compare/1.16.9...1.16.10) + +### Bug Fixes + +- Fix inventory `base_url` being ignored ([8870eb9](https://github.com/mkdocstrings/python/commit/8870eb9af837666f59f96149c67c849e02f7ee25) by Stefan Mejlgaard). [Issue-268](https://github.com/mkdocstrings/python/issues/268), [PR-269](https://github.com/mkdocstrings/python/pull/269) + ## [1.16.9](https://github.com/mkdocstrings/python/releases/tag/1.16.9) - 2025-04-03 [Compare with 1.16.8](https://github.com/mkdocstrings/python/compare/1.16.8...1.16.9) diff --git a/pyproject.toml b/pyproject.toml index 3ec25ccc..54f27585 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ maintain = [ "yore>=0.3.3", ] ci = [ - "blacK>=25.1", + "black>=25.1", "duty>=1.6", "ruff>=0.4", "pytest>=8.2", @@ -111,6 +111,7 @@ ci = [ "mkdocs-minify-plugin>=0.8", "mkdocs-redirects>=1.2", "mkdocs-section-index>=0.3", + "mkdocstrings>=0.29", # YORE: EOL 3.10: Remove line. "tomli>=2.0; python_version < '3.11'", ] diff --git a/src/mkdocstrings_handlers/python/_internal/config.py b/src/mkdocstrings_handlers/python/_internal/config.py index 11c77da1..210f8fe2 100644 --- a/src/mkdocstrings_handlers/python/_internal/config.py +++ b/src/mkdocstrings_handlers/python/_internal/config.py @@ -971,7 +971,7 @@ class Inventory: ), ] - base: Annotated[ + base_url: Annotated[ str | None, _Field( parent="inventories", @@ -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. diff --git a/tests/test_handler.py b/tests/test_handler.py index 5940af5e..f98ce545 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -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, @@ -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 @@ -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