6

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?

orome
  • 45,163
  • 57
  • 202
  • 418
  • Maybe you can use this: http://stackoverflow.com/a/25163963/407651 – mzjn Sep 25 '14 at 15:52
  • @mzjn: That's more than I was hoping for. Is there no decorator I can add to the variables. Or perhaps a flag in the RST? – orome Sep 25 '14 at 16:52
  • 1
    There is an "annotation" option but it's only for `autodata` and `autoattribute`: http://sphinx-doc.org/ext/autodoc.html?highlight=autodata#directive-autodata – mzjn Sep 25 '14 at 17:08
  • @mzjn: That looks like an answer! It's not perfect, since I need to give up then on auto-documenting members; but if that's all there is, it will serve. – orome Sep 25 '14 at 17:29

2 Answers2

2

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

JuanPi
  • 789
  • 1
  • 6
  • 19
  • This only works with Sphinx 3.5.0 and newer. Ubuntu 18.04 comes with 1.6 and 20.04 comes with 1.8, so there you're out of luck with the distributed sphinx. You can of course install newer sphinx via pip, but that may break other parts of your system. – Martin Pecka Sep 20 '22 at 18:29
  • @MartinPecka what you are doing is cross posting and it is not good behavior in this community. Please check the answer I left in your other verbatim comment. I think you are unaware of virtual environments – JuanPi Sep 21 '22 at 19:45
  • I'm quite aware of the negative view on cross-posting here, but I just felt it isn't so bad to inform people at both most relevant issues about the minimum version from which it works. Sorry if you feel it different. – Martin Pecka Sep 21 '22 at 21:23
1

Two solutions I can think of:

mzjn
  • 48,958
  • 13
  • 128
  • 248