fix: preserve symlink for include directive in relfn2path - #14638
Draft
aryansk wants to merge 1 commit into
Draft
Conversation
Fixes sphinx-doc#14520 Sphinx 8 changed relfn2path to use Path.resolve() which follows symlinks. For doc/README.rst -> ../README.rst (outside doc srcdir), abs_fn resolved to the target outside doc, so rel_fn became ../README.rst and note_included failed to map it to the README docname found via discover (README from doc/README.rst). This caused 'toc.not_included' warnings for symlinked README included via .. include::. Change relfn2path to use os.path.normpath without resolving symlinks, so abs_fn stays as doc/README.rst (the symlink path) and rel_fn is README.rst, correctly mapping to the README docname. Validation: demo https://github.com/tech-writing/sphinx-symlink-regression now builds with -W on Sphinx 8.2.3 and patched 9.1.1 (was 1 warning before, 0 after); git diff --check clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14520
Problem
Within
doc/index.rst, we are including adoc/README.rstfile, which is actually a symlink to the same file in the root directory. This layout works well until Sphinx 7, but starts failing on Sphinx 8 when running with-W:doc/README.rst: WARNING: document isn't included in any toctree [toc.not_included].Demo: https://github.com/tech-writing/sphinx-symlink-regression —
doc/README.rst -> ../README.rstwith.. include:: README.rstindoc/index.rst.Change
sphinx/environment/__init__.py:relfn2path— changePath(...).resolve()toPath(os.path.normpath(...))(viaPath(...).absolute()+os.path.normpath) soabs_fnstays asdoc/README.rst(the symlink path inside srcdir) rather than resolving to../README.rstoutside srcdir. This preservesrel_fnasREADME.rstandnote_includedcorrectly maps to theREADMEdocname found viadiscover(which findsREADME.rstindocas a file).Keep unrelated cleanup out of this PR.
Why this approach
Sphinx 8 changed
relfn2pathto usePath.resolve()which follows symlinks. Fordoc/README.rst -> ../README.rst,resolve()makesabs_fnthe target outside srcdir, so_relative_pathbecomes../README.rstandpath2docfails to map toREADME. Usingnormpathwithout resolving keeps the symlink path inside srcdir, matchingdiscover'sREADMEdocname and fixingtoc.not_included.Testing
Documentation and release impact
Review notes