mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
intersphinx: Create an `_InventoryItem
` type (#13248)
This commit is contained in:
@@ -28,6 +28,7 @@ from sphinx.ext.intersphinx._load import (
|
||||
)
|
||||
from sphinx.ext.intersphinx._resolve import missing_reference
|
||||
from sphinx.ext.intersphinx._shared import _IntersphinxProject
|
||||
from sphinx.util.inventory import _InventoryItem
|
||||
|
||||
from tests.test_util.intersphinx_data import (
|
||||
INVENTORY_V2,
|
||||
@@ -155,11 +156,11 @@ def test_missing_reference(tmp_path, app):
|
||||
load_mappings(app)
|
||||
inv = app.env.intersphinx_inventory
|
||||
|
||||
assert inv['py:module']['module2'] == (
|
||||
'foo',
|
||||
'2.0',
|
||||
'https://docs.python.org/foo.html#module-module2',
|
||||
'-',
|
||||
assert inv['py:module']['module2'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='2.0',
|
||||
uri='https://docs.python.org/foo.html#module-module2',
|
||||
display_name='-',
|
||||
)
|
||||
|
||||
# check resolution when a target is found
|
||||
|
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from sphinx.ext.intersphinx._shared import InventoryAdapter
|
||||
from sphinx.testing.util import SphinxTestApp
|
||||
from sphinx.util.inventory import _InventoryItem
|
||||
|
||||
from tests.utils import http_server
|
||||
|
||||
@@ -18,7 +19,6 @@ if TYPE_CHECKING:
|
||||
from collections.abc import Iterable
|
||||
from typing import BinaryIO
|
||||
|
||||
from sphinx.util.typing import InventoryItem
|
||||
|
||||
BASE_CONFIG = {
|
||||
'extensions': ['sphinx.ext.intersphinx'],
|
||||
@@ -109,10 +109,14 @@ class IntersphinxProject:
|
||||
"""The :confval:`intersphinx_mapping` record for this project."""
|
||||
return {self.name: (self.url, self.file)}
|
||||
|
||||
def normalise(self, entry: InventoryEntry) -> tuple[str, InventoryItem]:
|
||||
def normalise(self, entry: InventoryEntry) -> tuple[str, _InventoryItem]:
|
||||
"""Format an inventory entry as if it were part of this project."""
|
||||
url = posixpath.join(self.url, entry.uri)
|
||||
return entry.name, (self.safe_name, self.safe_version, url, entry.display_name)
|
||||
return entry.name, _InventoryItem(
|
||||
project_name=self.safe_name,
|
||||
project_version=self.safe_version,
|
||||
uri=posixpath.join(self.url, entry.uri),
|
||||
display_name=entry.display_name,
|
||||
)
|
||||
|
||||
|
||||
class FakeInventory:
|
||||
|
Reference in New Issue
Block a user