I'm currently using Sphinx (first time using it) to build the docs for my modules and I have some classes which have some class variables that are initialized with a default value.
For ex:
class ConfigSettings(object):
"""Class that manages a config file
"""
#: Contains the path to the config file (root dir of module)
path = Path(util.getAbsCurrentPath('configfile.ini'))
When building the docs the variable is evaluated and it prints the full path to the file which I don't want (for security reasons). Is there a way to not display the variable value but maybe only the annotation using Sphinx?
I tried various combinations of .. autoclass: and .. autodata: but none of them worked so far...
This is what I currently have in my build file:
Config module
----------------------------
.. automodule:: lib.config
:members:
:undoc-members:
:show-inheritance:
The easiest way with Sphinx directives is using annotation or excluding the member.
Unless there is a strict need to stop variables from self-initializing on module import, it's incorrect to change your Python source because of the way you want to present it. If your Python source code is correct, then adapt your .rst file to customize presentation.
your_module.py
from pathlib import Path
class YourClass:
#: This comment is documented with the member.
path = Path('your_path', 'configfile.ini')
your_module.rst (shows 2 possible ways).
your_module
===========
.. automodule:: your_module
:exclude-members: YourClass
.. autoclass:: YourClass
:exclude-members: path
In this example you use an annotation while excluding from autoclass.
.. autoattribute:: path
:annotation: ='write your path here'
.. autoclass:: YourClass
:noindex:
:exclude-members: path
In this example you simply exclude from autoclass.
The result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With