Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I omit the values of variables on Sphinx?

I have some module-level variables that have long and uninteresting values which I would like to exclude from auto-generated documentation. Is there a way to do this?

For example, in my Python source I have something like

#:This is a variable with a log value.
long_variable = "Some really long value that is not really of interest and just kind of gets in the way of reading and understanding what's going on."

and in my Sphinx source I have

.. automodule:: the_module
   :members:

and I want the documentation to omit the variable value.

How do I omit the value of variables on Sphinx? Is there ay way to do this in the Python source for specific variables; can I do it in the Sphinx source either for the whole module or for individual variables?

like image 645
orome Avatar asked Oct 20 '22 01:10

orome


2 Answers

To hide the contents of a variable use the meta info list field https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#info-field-lists.

An example can be found here https://stackoverflow.com/a/67999830/487993

like image 87
JuanPi Avatar answered Oct 22 '22 16:10

JuanPi


Two solutions I can think of:

  • Use the monkey patch for truncating long variable values suggested in this answer: https://stackoverflow.com/a/25163963/407651.

  • Document the module-level variable using autodata with the annotation option.

like image 40
mzjn Avatar answered Oct 22 '22 16:10

mzjn