开发者

In Sphinx documentation, is it possible to use the module name to specify a code sample to be included?

开发者 https://www.devze.com 2023-03-10 13:12 出处:网络
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,

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消