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:
@@ -6,7 +6,7 @@ import posixpath
|
||||
|
||||
import pytest
|
||||
|
||||
from sphinx.util.inventory import InventoryFile
|
||||
from sphinx.util.inventory import InventoryFile, _InventoryItem
|
||||
|
||||
|
||||
@pytest.mark.sphinx('dirhtml', testroot='builder-dirhtml')
|
||||
@@ -30,28 +30,33 @@ def test_dirhtml(app):
|
||||
invdata = InventoryFile.load(f, 'path/to', posixpath.join)
|
||||
|
||||
assert 'index' in invdata.get('std:doc', {})
|
||||
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
|
||||
assert invdata['std:doc']['index'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='path/to/',
|
||||
display_name='-',
|
||||
)
|
||||
|
||||
assert 'foo/index' in invdata.get('std:doc', {})
|
||||
assert invdata['std:doc']['foo/index'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'path/to/foo/',
|
||||
'-',
|
||||
assert invdata['std:doc']['foo/index'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='path/to/foo/',
|
||||
display_name='-',
|
||||
)
|
||||
|
||||
assert 'index' in invdata.get('std:label', {})
|
||||
assert invdata['std:label']['index'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'path/to/#index',
|
||||
'-',
|
||||
assert invdata['std:label']['index'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='path/to/#index',
|
||||
display_name='-',
|
||||
)
|
||||
|
||||
assert 'foo' in invdata.get('std:label', {})
|
||||
assert invdata['std:label']['foo'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'path/to/foo/#foo',
|
||||
'foo/index',
|
||||
assert invdata['std:label']['foo'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='path/to/foo/#foo',
|
||||
display_name='foo/index',
|
||||
)
|
||||
|
@@ -12,7 +12,7 @@ import pytest
|
||||
from sphinx._cli.util.errors import strip_escape_sequences
|
||||
from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
|
||||
from sphinx.errors import ConfigError
|
||||
from sphinx.util.inventory import InventoryFile
|
||||
from sphinx.util.inventory import InventoryFile, _InventoryItem
|
||||
|
||||
from tests.test_builders.xpath_data import FIGURE_CAPTION
|
||||
from tests.test_builders.xpath_util import check_xpath
|
||||
@@ -233,36 +233,36 @@ def test_html_inventory(app):
|
||||
'genindex',
|
||||
'search',
|
||||
}
|
||||
assert invdata['std:label']['modindex'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'https://www.google.com/py-modindex.html',
|
||||
'Module Index',
|
||||
assert invdata['std:label']['modindex'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='https://www.google.com/py-modindex.html',
|
||||
display_name='Module Index',
|
||||
)
|
||||
assert invdata['std:label']['py-modindex'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'https://www.google.com/py-modindex.html',
|
||||
'Python Module Index',
|
||||
assert invdata['std:label']['py-modindex'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='https://www.google.com/py-modindex.html',
|
||||
display_name='Python Module Index',
|
||||
)
|
||||
assert invdata['std:label']['genindex'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'https://www.google.com/genindex.html',
|
||||
'Index',
|
||||
assert invdata['std:label']['genindex'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='https://www.google.com/genindex.html',
|
||||
display_name='Index',
|
||||
)
|
||||
assert invdata['std:label']['search'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'https://www.google.com/search.html',
|
||||
'Search Page',
|
||||
assert invdata['std:label']['search'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='https://www.google.com/search.html',
|
||||
display_name='Search Page',
|
||||
)
|
||||
assert set(invdata['std:doc'].keys()) == {'index'}
|
||||
assert invdata['std:doc']['index'] == (
|
||||
'Project name not set',
|
||||
'',
|
||||
'https://www.google.com/index.html',
|
||||
'The basic Sphinx documentation for testing',
|
||||
assert invdata['std:doc']['index'] == _InventoryItem(
|
||||
project_name='Project name not set',
|
||||
project_version='',
|
||||
uri='https://www.google.com/index.html',
|
||||
display_name='The basic Sphinx documentation for testing',
|
||||
)
|
||||
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -8,7 +8,7 @@ import pytest
|
||||
|
||||
import sphinx.locale
|
||||
from sphinx.testing.util import SphinxTestApp
|
||||
from sphinx.util.inventory import InventoryFile
|
||||
from sphinx.util.inventory import InventoryFile, _InventoryItem
|
||||
|
||||
from tests.test_util.intersphinx_data import (
|
||||
INVENTORY_V1,
|
||||
@@ -23,17 +23,17 @@ if TYPE_CHECKING:
|
||||
|
||||
def test_read_inventory_v1():
|
||||
invdata = InventoryFile.loads(INVENTORY_V1, uri='/util')
|
||||
assert invdata['py:module']['module'] == (
|
||||
'foo',
|
||||
'1.0',
|
||||
'/util/foo.html#module-module',
|
||||
'-',
|
||||
assert invdata['py:module']['module'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='1.0',
|
||||
uri='/util/foo.html#module-module',
|
||||
display_name='-',
|
||||
)
|
||||
assert invdata['py:class']['module.cls'] == (
|
||||
'foo',
|
||||
'1.0',
|
||||
'/util/foo.html#module.cls',
|
||||
'-',
|
||||
assert invdata['py:class']['module.cls'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='1.0',
|
||||
uri='/util/foo.html#module.cls',
|
||||
display_name='-',
|
||||
)
|
||||
|
||||
|
||||
@@ -41,35 +41,35 @@ def test_read_inventory_v2():
|
||||
invdata = InventoryFile.loads(INVENTORY_V2, uri='/util')
|
||||
|
||||
assert len(invdata['py:module']) == 2
|
||||
assert invdata['py:module']['module1'] == (
|
||||
'foo',
|
||||
'2.0',
|
||||
'/util/foo.html#module-module1',
|
||||
'Long Module desc',
|
||||
assert invdata['py:module']['module1'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='2.0',
|
||||
uri='/util/foo.html#module-module1',
|
||||
display_name='Long Module desc',
|
||||
)
|
||||
assert invdata['py:module']['module2'] == (
|
||||
'foo',
|
||||
'2.0',
|
||||
'/util/foo.html#module-module2',
|
||||
'-',
|
||||
assert invdata['py:module']['module2'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='2.0',
|
||||
uri='/util/foo.html#module-module2',
|
||||
display_name='-',
|
||||
)
|
||||
assert invdata['py:function']['module1.func'][2] == (
|
||||
assert invdata['py:function']['module1.func'].uri == (
|
||||
'/util/sub/foo.html#module1.func'
|
||||
)
|
||||
assert invdata['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc'
|
||||
assert invdata['std:term']['a term'][2] == '/util/glossary.html#term-a-term'
|
||||
assert invdata['std:term']['a term including:colon'][2] == (
|
||||
assert invdata['c:function']['CFunc'].uri == '/util/cfunc.html#CFunc'
|
||||
assert invdata['std:term']['a term'].uri == '/util/glossary.html#term-a-term'
|
||||
assert invdata['std:term']['a term including:colon'].uri == (
|
||||
'/util/glossary.html#term-a-term-including-colon'
|
||||
)
|
||||
|
||||
|
||||
def test_read_inventory_v2_not_having_version():
|
||||
invdata = InventoryFile.loads(INVENTORY_V2_NO_VERSION, uri='/util')
|
||||
assert invdata['py:module']['module1'] == (
|
||||
'foo',
|
||||
'',
|
||||
'/util/foo.html#module-module1',
|
||||
'Long Module desc',
|
||||
assert invdata['py:module']['module1'] == _InventoryItem(
|
||||
project_name='foo',
|
||||
project_version='',
|
||||
uri='/util/foo.html#module-module1',
|
||||
display_name='Long Module desc',
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user