【问题标题】:Python Sphinx exclude patternsPython Sphinx 排除模式
【发布时间】:2017-05-05 09:41:17
【问题描述】:

我正在使用 Sphinx 为具有如下结构的项目生成文档:

+ project
|
+- docs
|
+- tests
|
+- workflow -+- definitions -+- <some folders>
             | 
             +- <rest of the project>

我想从文档中排除测试和工作流程/定义。

我尝试在 docs/conf.py 中排除模式

exclude_patterns = ['**/workflow/definitions', 'workflow/definitions', '*workflow/definitions', 'workflow/definitions*', 'workflow/definitions/*', 'workflow/definitions/*.*']

但即使工作流/定义仍然是自动生成的。

有人可以告诉我正确的排除模式如何忽略“定义”文件夹吗?

【问题讨论】:

  • exclude_patterns 只能用于排除 RST 文件(运行 sphinx-build 时)。工作流/定义目录是否包含 Python 文件或 RST 文件?

标签: python python-sphinx exclusionpath


【解决方案1】:

exclude_patterns 可用于从 sphinx-build 处理中排除源文件(reStructuredText 文件)。

exclude_patterns 在使用sphinx-apidoc 从 Python 模块生成 reStructuredText 文件时无效(但您可以告诉 sphinx-apidoc 某些路径名应该从生成中排除)。

【讨论】:

  • but you can tell sphinx-apidoc that certain pathnames should be excluded from the generation 你是怎么做到的?我在apidoc pagesautodoc config docs 都找不到任何东西。
  • 对于遇到与我类似问题的其他人,EXCLUDE_PATTERN 也需要包含模块路径。例如 sphinx-apidoc -f -o source .. *setup* 仍然从 setup.py 生成 setup.rst,但 sphinx-apidoc -f -o source .. ../*setup* 按预期工作。
【解决方案2】:

请参阅sphinx-apidoc --help 中的 EXCLUDE_PATTERN

usage: sphinx-apidoc [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...]

The <EXCLUDE_PATTERN>s can be file and/or directory patterns that will be excluded from generation.

【讨论】:

    【解决方案3】:

    exclude_patterns 的文档表明 'workflow/definitions' 应该忽略该目录,假设源文件都以 .rst 结尾。

    您可以configure the source file suffices as a list:

    source_suffix = ['.rst', '.txt']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 2017-12-20
      • 2012-09-06
      • 1970-01-01
      • 2020-03-24
      • 2011-06-20
      • 2021-12-25
      • 2014-01-05
      相关资源
      最近更新 更多