Does sphinx allow nested includes ?
I have a hierarchy that looks like that:
~> root
|_conf.py
|_index.rst
|_level1.rst
|_level2
|_level2.rst
|_level3
|_level3.rst
Files look this way:
~> more conf.py
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('level1'))
sys.path.insert(0, os.path.abspath('level1/level2'))
sys.path.insert(0, os.path.abspath('level1/level2/level3'))
project = 'PM'
copyright = '2020, PM'
author = 'PM'
extensions = [
]
templates_path = ['_templates']
exclude_patterns = ['_build']
Note: all sublevels are added in sys.path.
The index just adds level1.
~> more index.rst
Welcome to PM's documentation!
==============================
.. toctree::
:maxdepth: 6
:caption: Contents:
level1
And the rst files look like :
~> more level1.rst
level1
######
this is level1
.. include:: level2/level2.rst
~> more level2/level2.rst
level2
======
this is level2
.. include:: level3/level3.rst
~> more .\level2\level3\level3.rst
level3
------
this is level3
The compilation emits this warning :
~> make latexpdf
...
reading sources... [100%] level2/level3/level3
level2/level2.rst:6: WARNING: Problems with "include" directive path:
InputError: [Errno 2] No such file or directory: 'level3/level3.rst'.
...
Table of content is OK down to level 2 :
1 level1
1.1 level2
But level 3 is missing:
1.1.1 level3
Level 3 is ignored.
Is there a way to get this to work ? This way or another ? Or any workaround ? For instance is there a way to say "pwd is now level2" in level2.rst ?
UPDATE
Real life application looks more like:
~> root
|_conf.py
|_index.rst
|_level1.rst
|_level2
| |_conf.py
| |_index.rst
| |_level2.rst
| |_level3
| |_conf.py
| |_index.rst
| |_level3.rst
|_level4
|_conf.py
|_index.rst
|_level4.rst
|_level3
|_conf.py
|_index.rst
|_level3.rst
level3
is actually a git-submodule
that is cloned into both level2
and level4
but on different branches where the doc may not be the same.
Ideally, level3
should generate his own doc. level2
and level4
should generate his own doc including the one of level3
. level1
should generate his own doc including the ones of both level2
(which embed doc of level3
) and level4
(which embed doc of level3
).
This is why all paths are relatives in my first simplified attempt.
I try to understand if this (ideal case) could be possible.