2

I'd like to include a code example in my sphinx documentation. I don't, however, want to refer to the file by its path, but would rather specify it by its module name.

That is, instead of doing it the way indicated here Showing code examples

.. literalinclude example.py

or

.. literalinclude ../../example.py

I'd rather do (for example)

.. includemodule mymodule.example

Is this possible to do without writing a custom extension? Or, what is the simplest way to write such an extension?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Ed L
  • 1,947
  • 2
  • 17
  • 30

1 Answers1

0

You can reference other classes by using something like this:

:class:`~module.submodule.Class`

If you add the examples as doctest to the class than you have examples which are guaranteed to work since they are directly runnable.

Wolph
  • 78,177
  • 11
  • 137
  • 148
  • 1
    How does this help my problem? – Ed L Jun 03 '11 at 00:44
  • @Ed L: You could link to the specific module and put the example in there. It will both work as documentation and as test if you use doctests. – Wolph Jun 03 '11 at 15:37