I'm wondering if it's possible to use a dynamic path in a Sphinx and/or RST ..include::
directive?
My reason for this is I have some developer documentation generated by Sphinx in one repo, but we have a bunch of unit tests in another repo that we want to include in the docs. If I know the path to the file in the other repo, it's pretty standard, like this:
Some text in my RST file
.. include:: ../path/to/other/repo/file.py
:code: python
Some more text
The problem is the relative path to the other repo is not always the same, depending on how things are cloned and installed. For example, on Read The Docs, the other repo is installed in editable mode via requirements.txt
into a /src
subfolder, locally the repo is in a git folder, etc.
I can add logic into the conf.py
file to find the other repo and set a pointer which I can use in the RST files, but I can't figure out if it's possible to have a dynamic path in the ..include::
?
So far the only workaround I can think of is to have my conf.py
find the other repo and create a symlink which I reference in the RST files, which is fine, but I wonder if there's a better way?