1

I'm using Sphinx to generate docs for a repository. The Sphinx toctree allows the use of :glob: to auto-select certain docs.

I have a toctree of the form

.. toctree::
     :maxdepth: 1
     :glob:

     _generated/some/repository/structure/*/doc/acme_corp_*

where the first * gets all of the different modules located in /some/repository/structure and I want all the docs from modules that begin with acme_corp_.

However, this grabs both packages and modules when the toctree outputs. I've tried using _generated/some/repository/structure/*/doc/acme_corp_*package but that outputs no matching links (since I guess that the word package does not actually appear in the path).

How can I get Sphinx to auto-generate a maxdepth: 1 toctree such that I only get the packages in the resulting table of contents?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
brunston
  • 1,244
  • 1
  • 10
  • 18

1 Answers1

1

As a toctree footnotes states:

A note on available globbing syntax: you can use the standard shell constructs *, ?, [...] and [!...] with the feature that these all don’t match slashes. A double star ** can be used to match any sequence of characters including slashes.

So, it's just a matter of getting the glob syntax correct. If you only want to match on python packages, which are folders containing __init__.py and other .py files, this might work:

.. toctree::
     :maxdepth: 1
     :glob:

     _generated/some/repository/structure/*/doc/acme_corp_*/

If you want to only match on python modules, which are module_name.py files, this might work:

.. toctree::
     :maxdepth: 1
     :glob:

     _generated/some/repository/structure/*/doc/acme_corp_*.py

I can't duplicate this since I don't know your exact project structure, but read up on glob syntax and try different combinations based off of what files/folder patterns you would like to include.

David Vitale
  • 176
  • 2
  • 3