Skip to content

Commit aa8ac78

Browse files
authored
Fix InventoryItem deprecation warning (#173)
1 parent a1ef88d commit aa8ac78

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

contributing.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ For tips and tricks on contributing, see `how to submit a contribution
3737
specifically `opening a pull request
3838
<https://opensource.guide/how-to-contribute/#opening-a-pull-request>`_.
3939

40+
If you want to contribute to someone else's fork and find yourself forgetting
41+
how to do it every time, here's the runbook:
42+
43+
.. code:: sh
44+
45+
git remote add [name] [email protected]:[name]/sphinx-codeautolink.git
46+
git fetch [name]
47+
git switch -c branch [name]/branch
48+
git remote rm [name]
49+
4050
Testing
4151
-------
4252
The installation can be verified, and any changes tested by running tox.

docs/src/release_notes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sphinx-codeautolink adheres to
1010

1111
Unreleased
1212
----------
13+
- Fix Sphinx InventoryItem deprecation warning (:issue:`173`)
1314
- Add support for the DIRHTML Sphinx builder (:issue:`188`)
1415

1516
0.17.2 (2025-03-02)

pyproject.toml

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

5255
[tool.coverage.run]
5356
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()
@@ -296,7 +299,9 @@ def apply_links(self, app, exception) -> None:
296299
self.cache.write()
297300

298301

299-
def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
302+
def transpose_inventory(
303+
inv: dict, relative_to: str, *, use_tuple: bool = False
304+
) -> dict[str, str]:
300305
"""
301306
Transpose Sphinx inventory from {type: {name: (..., location)}} to {name: location}.
302307
@@ -308,13 +313,18 @@ def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
308313
Sphinx inventory
309314
relative_to
310315
if a local file is found, transform it to be relative to this dir
316+
use_tuple
317+
force using Sphinx inventory tuple interface,
318+
TODO: move to class interface if it becomes public (#173)
311319
"""
312320
transposed = {}
313321
for type_, items in inv.items():
314322
if not type_.startswith("py:"):
315323
continue
316324
for item, info in items.items():
317-
location = info[2]
325+
location = (
326+
info.uri if not use_tuple and sphinx_version >= (8, 2) else info[2]
327+
)
318328
if not location.startswith("http"):
319329
location = str(Path(location).relative_to(relative_to))
320330
transposed[item] = location

0 commit comments

Comments
 (0)