canyon289
canyon289

Reputation: 3505

Mocking internal modules when using Sphinx Autodoc

My python package has a module called settings.py which looks for a settings.ini file, and if one isn't found raises an Exception.

My package works fine but when I try and use Sphinx Autodoc it fails because it can't find a settings file.

What options do I have for getting around this? The ones I can think of are

  1. Put a settings.ini file in one of the Sphinx directories so it can be read.
  2. Somehow mock the internal settings module if possible. The settings module is unimportant so I don't care if there is no documentation for it to the suer

Has anyone run into a similar issue when trying to generate Sphinx documentation on packages that need external files and if so what is your solution?

Upvotes: 1

Views: 418

Answers (1)

Steve Piercy
Steve Piercy

Reputation: 15055

Pyramid has a command-line script pserve which loads an .ini settings file.

To document this script, we use autoprogram as follows:

.. autoprogram:: pyramid.scripts.pserve:PServeCommand.parser
    :prog: pserve

and in your conf.py:

extensions = [
...
    'sphinxcontrib.autoprogram',
...
]

It requires the use of argparse in your script.

Upvotes: 2

Related Questions