Can Sphinx emit the 'module contents' first and the 'submodules' last?

Updated Answer (thank you, Donal Fellows):

https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html#cmdoption-sphinx-apidoc-M

Original Answer:

Yes, there is an option to do this, it's just not documented here. Inside my copy of Sphinx-1.3.3/sphinx/apidoc.py I found this:

parser.add_option('-M', '--module-first', action='store_true',
                  dest='modulefirst',
                  help='Put module documentation before submodule '
                  'documentation')

I tried it and it works like a charm.


It is also possible to add this option in the conf.py file.

Search in conf.py for the line where the string containing the sphinx-apidoc command is (located in a try section) and add the "--module-first" option.

The new line will look like this:

cmd_line_template = "sphinx-apidoc --module-first -f -o {outputdir} {moduledir}"