hiro protagonist
hiro protagonist

Reputation: 46849

sphinx: document data in python without displaying the data

i know i can document (module) constants in sphinx with either

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

or

primes =  (2, 3, 5, 7, 11, 13, 17)
"""a tuple of primes"""

which will then appear in the sphinx generated documentation; i.e. it will look something like this:

somemodule.primes

= (2, 3, 5, 7, 11, 13, 17)

a tuple of primes

but what if the data is a very long list? then i would like to be able to have a docstring in the documentation but not have the actual data itself in the doc.

this is what i would like to have in the doc:

somemodule.primes

a tuple of primes

is there a way i can achieve this?


for completeness:

i ran sphinx-quickstart and enabled autodoc:

autodoc: automatically insert docstrings from modules (y/n) [n]: y

the only thing i have added to index.rst is:

``somemodule``
**************

.. automodule:: somemodule
    :members:

and somemodule.py contains this:

#: a tuple of primes
primes = (2, 3, 5, 7, 11, 13, 17)

then i adapted sys.path in conf.py such that somemodule.py is in that path.

Upvotes: 5

Views: 1309

Answers (2)

JuanPi
JuanPi

Reputation: 781

Just in case somebody ends up here. To hide the contents of a variable use the meta info list field.

Example:

primes = (2, 3, 5, 7, 11, 13, 17)
"""A tuple of primes.

   :meta hide-value:
"""

Upvotes: 6

hiro protagonist
hiro protagonist

Reputation: 46849

i ended not having any documentation for somemodule.primes in somemodule.py (which makes sphinx ignore it) and putting a manual documentation into index.rst

``somemodule``
**************

.. automodule:: somemodule
    :members:

.. py:data:: somemodule.primes

    a tuple of primes

so far i found no way doing something similar directly in somemodule.py.

Upvotes: 1

Related Questions