Skip to content

Commit fec80fd

Browse files
committed
Fix InventoryItem deprecation warning (#173)
1 parent 47d3293 commit fec80fd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Fix Sphinx InventoryItem deprecation warning (:issue:`173`)
14+
1115
0.17.2 (2025-03-02)
1216
-------------------
1317
- Support :rst:dir:`testsetup` from ``sphinx.ext.doctest`` as another

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ version = {attr = "sphinx_codeautolink.__version__"}
4848
[tool.pytest.ini_options]
4949
python_files = "*.py"
5050
testpaths = ["tests"]
51+
filterwarnings = [
52+
"error",
53+
"ignore:.*IPython:UserWarning",
54+
]
5155

5256
[tool.coverage.run]
5357
source = ["src"]

src/sphinx_codeautolink/extension/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from traceback import print_exc
99

10+
from sphinx import version_info as sphinx_version
1011
from sphinx.ext.intersphinx import InventoryAdapter
1112
from sphinx.util import import_object
1213

@@ -177,7 +178,9 @@ def make_inventory(app):
177178
}
178179
inter_inv = InventoryAdapter(app.env).main_inventory
179180
transposed = transpose_inventory(inter_inv, relative_to=app.outdir)
180-
transposed.update(transpose_inventory(inventory, relative_to=app.outdir))
181+
transposed.update(
182+
transpose_inventory(inventory, relative_to=app.outdir, use_tuple=True)
183+
)
181184
return transposed
182185

183186
@print_exceptions()
@@ -294,7 +297,9 @@ def apply_links(self, app, exception) -> None:
294297
self.cache.write()
295298

296299

297-
def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
300+
def transpose_inventory(
301+
inv: dict, relative_to: str, *, use_tuple: bool = False
302+
) -> dict[str, str]:
298303
"""
299304
Transpose Sphinx inventory from {type: {name: (..., location)}} to {name: location}.
300305
@@ -306,13 +311,18 @@ def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
306311
Sphinx inventory
307312
relative_to
308313
if a local file is found, transform it to be relative to this dir
314+
use_tuple
315+
force using Sphinx inventory tuple interface,
316+
TODO: move to class interface if it becomes public (#173)
309317
"""
310318
transposed = {}
311319
for type_, items in inv.items():
312320
if not type_.startswith("py:"):
313321
continue
314322
for item, info in items.items():
315-
location = info[2]
323+
location = (
324+
info.uri if not use_tuple and sphinx_version >= (8, 2) else info[2]
325+
)
316326
if not location.startswith("http"):
317327
location = str(Path(location).relative_to(relative_to))
318328
transposed[item] = location

0 commit comments

Comments
 (0)