【问题标题】:Sphinx documentation and autodoc-skip-memberSphinx 文档和 autodoc-skip-member
【发布时间】:2023-03-26 00:23:01
【问题描述】:

我正在通过以下方式为 django 项目构建我的 sphinx 文档:

sphinx-apidoc app -o docs/source/app --force

现在它包含了我不想在我的文档中包含的所有南方迁移。我现在尝试通过以下方式排除它们:

conf.py:
    def skip_migrations(app, what, name, obj, skip, options):
        return skip or (what == 'module' and name.find('Migration') != -1)\ 
               or str(obj).find('migrations') != -1

    def setup(app):
       app.connect('autodoc-skip-member', skip_migrations)

现在它们不再被记录,但仍列在模块下。如何排除它们?

【问题讨论】:

    标签: django python-sphinx documentation-generation sphinx-apidoc


    【解决方案1】:

    您可以排除为迁移创建的第一个文件,方法是将它们添加到 conf.py 文件中的 exclude_pattern:

    exclude_patterns = ["**/*.migrations.rst",]
    

    【讨论】:

      【解决方案2】:

      首先避免使用sphinx-apidoc 生成.rst 文件:

      sphinx-apidoc app -o docs/source/app --force */migrations/*
      

      在模块名称之后添加的模式被理解为排除路径。

      【讨论】:

      • 对于那些在我之后的人:--force 需要在 -o 之前,否则此命令将失败。正如this issue 中所解释的,它与 argparse 有关。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-16
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多