Displaying dictionary data in Sphinx documentation

后端 未结 4 522
感动是毒
感动是毒 2020-12-10 13:15

I have a dictionary in Python project source code which describes default configuration values. The dictionary is quite lengthy. I\'d like to see dictionary in Sphinx docume

4条回答
  •  [愿得一人]
    2020-12-10 13:27

    y'all i have done it but you are not going to believe me because it is literally five lines with imports. roast me in the replies but this has been working for a week or two and i haven't noticed it breaking anything.

    This is in conf.py :

    from pprint import pformat
    def object_description(object) -> str:
        return pformat(object, indent=4)
    
    from sphinx.util import inspect
    inspect.object_description = object_description
    

    this takes yer ~uh oh~

    image of sphinx docs without pretty formatting

    into a ~uh huh~

    image of sphinx docs with pretty formatting

    edit: fixed images b/c got the ~rep~ enough to have them

提交回复
热议问题