File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import os
2+ import pathlib
23import urllib
34
45import sphinx.application
@@ -52,9 +53,12 @@ def resolve_local_html_link(app: sphinx.application.Sphinx, url_path: str) -> st
5253def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str:
5354 """Replace remote URIs targeting https://packaging.python.org/en/latest/...
5455 with local ones, so that local changes are taken into account by linkcheck.
56+
57+ Additionally, resolve local relative links to html_extra_path.
5558 """
5659 local_uri = uri
5760 parsed = urllib.parse.urlparse(uri)
61+ # Links to https://packaging.python.org/en/latest/...
5862 if parsed.hostname == DOMAIN and parsed.path.startswith("/en/latest/"):
5963 document = parsed.path.removeprefix("/en/latest/")
6064 local_uri = resolve_local_html_link(app, document)
@@ -64,6 +68,12 @@ def rewrite_local_uri(app: sphinx.application.Sphinx, uri: str) -> str:
6468 "into account (pass -vv for more info)"
6569 )
6670 logger.debug(f"Replacing linkcheck URL {uri!r} with {local_uri!r}")
71+ # Local relative links
72+ if not parsed.scheme and not parsed.netloc and parsed.path:
73+ full_path = pathlib.Path(app.env.docname).parent / parsed.path
74+ local_uri = resolve_local_html_link(app, os.fspath(full_path))
75+ if local_uri != uri:
76+ logger.verbose(f"Local linkcheck URL {uri!r} resolved as {local_uri!r}")
6777 return local_uri
6878
6979
You can’t perform that action at this time.
0 commit comments