Merge pull request #2056 from erosennin/intersphinx-fix-relative-path

Fix relative paths in intersphinx links
This commit is contained in:
Takeshi KOMIYA 2016-09-14 10:54:18 +09:00 committed by GitHub
commit c832d36d19
2 changed files with 16 additions and 1 deletions

View File

@ -332,7 +332,7 @@ def missing_reference(app, env, node, contnode):
proj, version, uri, dispname = inventory[objtype][target]
if '://' not in uri and node.get('refdoc'):
# get correct path in case of subdirectories
uri = path.join(relative_path(node['refdoc'], env.srcdir), uri)
uri = path.join(relative_path(node['refdoc'], '.'), uri)
newnode = nodes.reference('', '', internal=False, refuri=uri,
reftitle=_('(in %s v%s)') % (proj, version))
if node.get('refexplicit'):

View File

@ -134,6 +134,8 @@ def test_missing_reference(tempdir, app, status, warning):
app.config.intersphinx_mapping = {
'https://docs.python.org/': inv_file,
'py3k': ('https://docs.python.org/py3k/', inv_file),
'py3krel': ('py3k', inv_file), # relative path
'py3krelparent': ('../../py3k', inv_file), # relative path, parent dir
}
app.config.intersphinx_cache_limit = 0
@ -201,6 +203,19 @@ def test_missing_reference(tempdir, app, status, warning):
assert rn is None
assert contnode[0].astext() == 'py3k:unknown'
# check relative paths
rn = reference_check('py', 'mod', 'py3krel:module1', 'foo')
assert rn['refuri'] == 'py3k/foo.html#module-module1'
rn = reference_check('py', 'mod', 'py3krelparent:module1', 'foo')
assert rn['refuri'] == '../../py3k/foo.html#module-module1'
rn = reference_check('py', 'mod', 'py3krel:module1', 'foo', refdoc='sub/dir/test')
assert rn['refuri'] == '../../py3k/foo.html#module-module1'
rn = reference_check('py', 'mod', 'py3krelparent:module1', 'foo', refdoc='sub/dir/test')
assert rn['refuri'] == '../../../../py3k/foo.html#module-module1'
@with_app()
@with_tempdir