【问题标题】:How to add inheritance diagram to all modules in Sphinx?如何将继承图添加到 Sphinx 中的所有模块?
【发布时间】:2019-12-12 15:10:41
【问题描述】:

所以我一直试图让Sphinx在通过sphinx-apidoc生成.rst文件时为所有子模块/类生成继承图,类似于这个example。但我没有在 Sphinx 中找到任何内置功能来执行此操作。

我找到的最接近的解决方案是manually在代码中为每个类文档字符串添加一个带有类名的继承图行,但这不是很方便。

所以问题是如何将继承图添加到所有模块 .rst 文件?

【问题讨论】:

  • 如果您有问题及其解决方案,可以同时发布。但不要在问题中包含解决方案。先发问题,再发答案。这就是 Stack Overflow 的工作原理(顺便说一句,欢迎!)。
  • 是的,第一次发帖,感谢您的意见 :) 下次会这样做!
  • 不要等到下一次。您应该删除此问题的“答案部分”并将其放入正确的答案中。

标签: graph python-sphinx diagram docstring read-the-docs


【解决方案1】:

找到解决问题的方法:

  1. 转到文件夹/usr/local/lib/python3.6/dist-packages/sphinx/templates/apidoc/
  2. 打开package.rst_t
  3. *{{- [submodule, "module"] | join(" ") | e | heading(2) }}*之后添加:

    .. inheritance-diagram:: {{submodule}}
    
       :parts: 1
    

在制作html文件时还需要在conf.py文件中添加这些扩展:

extensions = ['sphinx.ext.graphviz','sphinx.ext.inheritance_diagram']

为了使图表更具可读性,我还将其添加到 conf.py(TB=Top to bottom view):

inheritance_graph_attrs = dict(rankdir="TB", size='""')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    • 1970-01-01
    相关资源
    最近更新 更多