Skip to content

Fix InventoryItem deprecation warning (#173) #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ For tips and tricks on contributing, see `how to submit a contribution
specifically `opening a pull request
<https://opensource.guide/how-to-contribute/#opening-a-pull-request>`_.

If you want to contribute to someone else's fork and find yourself forgetting
how to do it every time, here's the runbook:

.. code:: sh

git remote add [name] [email protected]:[name]/sphinx-codeautolink.git
git fetch [name]
git switch -c branch [name]/branch
git remote rm [name]

Testing
-------
The installation can be verified, and any changes tested by running tox.
Expand Down
1 change: 1 addition & 0 deletions docs/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sphinx-codeautolink adheres to

Unreleased
----------
- Fix Sphinx InventoryItem deprecation warning (:issue:`173`)
- Add support for the DIRHTML Sphinx builder (:issue:`188`)

0.17.2 (2025-03-02)
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ version = {attr = "sphinx_codeautolink.__version__"}
[tool.pytest.ini_options]
python_files = "*.py"
testpaths = ["tests"]
filterwarnings = [
"ignore:.*IPython:UserWarning",
]

[tool.coverage.run]
source = ["src"]
Expand Down
16 changes: 13 additions & 3 deletions src/sphinx_codeautolink/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from traceback import print_exc

from sphinx import version_info as sphinx_version
from sphinx.ext.intersphinx import InventoryAdapter
from sphinx.util import import_object

Expand Down Expand Up @@ -177,7 +178,9 @@ def make_inventory(app):
}
inter_inv = InventoryAdapter(app.env).main_inventory
transposed = transpose_inventory(inter_inv, relative_to=app.outdir)
transposed.update(transpose_inventory(inventory, relative_to=app.outdir))
transposed.update(
transpose_inventory(inventory, relative_to=app.outdir, use_tuple=True)
)
return transposed

@print_exceptions()
Expand Down Expand Up @@ -296,7 +299,9 @@ def apply_links(self, app, exception) -> None:
self.cache.write()


def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
def transpose_inventory(
inv: dict, relative_to: str, *, use_tuple: bool = False
) -> dict[str, str]:
"""
Transpose Sphinx inventory from {type: {name: (..., location)}} to {name: location}.

Expand All @@ -308,13 +313,18 @@ def transpose_inventory(inv: dict, relative_to: str) -> dict[str, str]:
Sphinx inventory
relative_to
if a local file is found, transform it to be relative to this dir
use_tuple
force using Sphinx inventory tuple interface,
TODO: move to class interface if it becomes public (#173)
"""
transposed = {}
for type_, items in inv.items():
if not type_.startswith("py:"):
continue
for item, info in items.items():
location = info[2]
location = (
info.uri if not use_tuple and sphinx_version >= (8, 2) else info[2]
)
if not location.startswith("http"):
location = str(Path(location).relative_to(relative_to))
transposed[item] = location
Expand Down
Loading