You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.. include:: directive shouldn't care about filename extension #8515
Replacing the extension on a.rst and b.rst with .txt suppresses the warnings. This is apparently because Sphinx scans files with the .rst extension twice. I hope you agree that is very confusing, and the user should be able to use the .rst extension also for included files?
changed the title [-]Invalid "WARNING: Undefined substitution referenced"[/-][+].. include:: directive shouldn't care about filename extension[/+]on Dec 10, 2020
My issue is that this is confusing behavior. How should the user know that they shouldn't use the .rst extension when .. include::ing a file? Why do they even need to think about this?
Sphinx simply shouldn't output a warning even if they included files have a .rst extension.
At present, Sphinx scans the target documents from the source directory by file extensions. After that, it reads them all. To prevent warnings (or skip processing), we need to know the "included" file before processing. How do we check it? I think it is hard to know until reading all of the target documents.
My issue is that this is confusing behavior. How should the user know that they shouldn't use the .rst extension when .. include::ing a file? Why do they even need to think about this?
Wow, thanks! That was the issue. Warnings were counter-intuitive insofar as possible. Changed extensions of files invoked by "include" to .rsti, it helped
A future improvement could be that such warnings are delayed as much as possible but it's very difficult since it would require more post-processing (and won't be worth the effort most of the time).
With tk0miya's answer, I think this issue should be closed (you'll still get warnings/errors if you use rst documents like that, so it's an expected behaviour). However, I'll just change the labels and leave it open.
Activity
tk0miya commentedon Dec 8, 2020
Yes. As you quoted, Sphinx processes all
.rstfiles under the source directory. So the warnings are correct to me. What do you expect?[-]Invalid "WARNING: Undefined substitution referenced"[/-][+].. include:: directive shouldn't care about filename extension[/+]brechtm commentedon Dec 10, 2020
My issue is that this is confusing behavior. How should the user know that they shouldn't use the .rst extension when
.. include::ing a file? Why do they even need to think about this?Sphinx simply shouldn't output a warning even if they included files have a .rst extension.
tk0miya commentedon Dec 11, 2020
At present, Sphinx scans the target documents from the source directory by file extensions. After that, it reads them all. To prevent warnings (or skip processing), we need to know the "included" file before processing. How do we check it? I think it is hard to know until reading all of the target documents.
delameter commentedon Jul 20, 2022
Wow, thanks! That was the issue. Warnings were counter-intuitive insofar as possible. Changed extensions of files invoked by "include" to
.rsti, it helpedpicnixz commentedon Aug 16, 2023
A future improvement could be that such warnings are delayed as much as possible but it's very difficult since it would require more post-processing (and won't be worth the effort most of the time).
With tk0miya's answer, I think this issue should be closed (you'll still get warnings/errors if you use
rstdocuments like that, so it's an expected behaviour). However, I'll just change the labels and leave it open.jdillard commentedon Aug 26, 2026
Closing as expected behavior, but I made a docs PR, #14649, to give tips on how to avoid common issues if you want to give it a review.