How do I omit the values of variables on Sphinx?
Asked Answered
T

2

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?

Tripe answered 24/9, 2014 at 21:27 Comment(4)
Maybe you can use this: https://mcmap.net/q/1174255/-ellipsis-truncation-on-module-attribute-value-in-sphinx-generated-documentationLamellicorn
@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?Tripe
There is an "annotation" option but it's only for autodata and autoattribute: sphinx-doc.org/ext/…Lamellicorn
@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.Tripe
L
1

Two solutions I can think of:

Lamellicorn answered 26/9, 2014 at 19:44 Comment(0)
D
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://mcmap.net/q/1174256/-sphinx-document-data-in-python-without-displaying-the-data

Debutant answered 16/6, 2021 at 9:23 Comment(3)
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.Fourgon
@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 environmentsDebutant
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.Fourgon
L
1

Two solutions I can think of:

Lamellicorn answered 26/9, 2014 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.