Skip to content

Commit 8949df4

Browse files
authored
Fix intersphinx reftitle for non-numeric versions (#13737)
Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
1 parent 7b4164a commit 8949df4

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Contributors
103103
* Stefan Seefeld -- toctree improvements
104104
* Stefan van der Walt -- autosummary extension
105105
* Steve Piercy -- documentation improvements
106+
* Szymon Karpinski -- intersphinx improvements
106107
* \T. Powers -- HTML output improvements
107108
* Taku Shimizu -- epub3 builder
108109
* Thomas Lamb -- linkcheck builder

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Bugs fixed
9595
Patch by Jean-François B.
9696
* #13685: gettext: Correctly ignore trailing backslashes.
9797
Patch by Bénédikt Tran.
98+
* #13712: intersphinx: Don't add "v" prefix to non-numeric versions.
99+
Patch by Szymon Karpinski.
98100

99101
Testing
100102
-------

sphinx/ext/intersphinx/_resolve.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ def _create_element_from_result(
4646
# get correct path in case of subdirectories
4747
uri = (_relative_path(Path(), Path(node['refdoc']).parent) / uri).as_posix()
4848
if inv_item.project_version:
49-
reftitle = _('(in %s v%s)') % (inv_item.project_name, inv_item.project_version)
49+
if not inv_item.project_version[0].isdigit():
50+
# Do not append 'v' to non-numeric version
51+
version = inv_item.project_version
52+
else:
53+
version = f'v{inv_item.project_version}'
54+
reftitle = _('(in %s %s)') % (inv_item.project_name, version)
5055
else:
5156
reftitle = _('(in %s)') % (inv_item.project_name,)
5257

tests/test_extensions/test_ext_intersphinx.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
INVENTORY_V2,
3636
INVENTORY_V2_AMBIGUOUS_TERMS,
3737
INVENTORY_V2_NO_VERSION,
38+
INVENTORY_V2_TEXT_VERSION,
3839
)
3940
from tests.utils import http_server
4041

@@ -900,3 +901,25 @@ def log_message(*args, **kwargs):
900901
srcdir=None,
901902
cache_path=None,
902903
)
904+
905+
906+
@pytest.mark.sphinx('html', testroot='root')
907+
def test_inventory_text_version(tmp_path, app):
908+
inv_file = tmp_path / 'inventory'
909+
inv_file.write_bytes(INVENTORY_V2_TEXT_VERSION)
910+
set_config(
911+
app,
912+
{
913+
'python': ('https://docs.python.org/', str(inv_file)),
914+
},
915+
)
916+
917+
# load the inventory and check if non-numeric version is handled correctly
918+
validate_intersphinx_mapping(app, app.config)
919+
load_mappings(app)
920+
921+
rn = reference_check(app, 'py', 'mod', 'module1', 'foo')
922+
assert isinstance(rn, nodes.reference)
923+
assert rn['refuri'] == 'https://docs.python.org/foo.html#module-module1'
924+
assert rn['reftitle'] == '(in foo stable)'
925+
assert rn[0].astext() == 'Long Module desc'

tests/test_util/intersphinx_data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@
6262
b term std:term -1 document.html#id5 -
6363
B term std:term -1 document.html#B -
6464
""")
65+
66+
INVENTORY_V2_TEXT_VERSION: Final[bytes] = b"""\
67+
# Sphinx inventory version 2
68+
# Project: foo
69+
# Version: stable
70+
# The remainder of this file is compressed with zlib.
71+
""" + zlib.compress(b"""\
72+
module1 py:module 0 foo.html#module-module1 Long Module desc
73+
""")

0 commit comments

Comments
 (0)