7
7
from pathlib import Path
8
8
from traceback import print_exc
9
9
10
+ from sphinx import version_info as sphinx_version
10
11
from sphinx .ext .intersphinx import InventoryAdapter
11
12
from sphinx .util import import_object
12
13
@@ -177,7 +178,9 @@ def make_inventory(app):
177
178
}
178
179
inter_inv = InventoryAdapter (app .env ).main_inventory
179
180
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
+ )
181
184
return transposed
182
185
183
186
@print_exceptions ()
@@ -296,7 +299,9 @@ def apply_links(self, app, exception) -> None:
296
299
self .cache .write ()
297
300
298
301
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 ]:
300
305
"""
301
306
Transpose Sphinx inventory from {type: {name: (..., location)}} to {name: location}.
302
307
@@ -308,13 +313,18 @@ def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
308
313
Sphinx inventory
309
314
relative_to
310
315
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)
311
319
"""
312
320
transposed = {}
313
321
for type_ , items in inv .items ():
314
322
if not type_ .startswith ("py:" ):
315
323
continue
316
324
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
+ )
318
328
if not location .startswith ("http" ):
319
329
location = str (Path (location ).relative_to (relative_to ))
320
330
transposed [item ] = location
0 commit comments