Sphinx不删除html输出中的doctest标志

问题描述 投票:1回答:1

我无法消除html输出的doctest标志(即<BLANKLINE># doctest: +ELLIPSIS)。我能够生成所需的文档,因此没有错误,但其中包含我要删除的这些标志。 Sphinx文档here声称这是可能的,所以我必须做错了什么。我的文档示例为numpy样式,并且我尝试同时使用napoleon和numpydoc扩展名。

这是我已采取的步骤。

  1. 运行sphinx-quickstart(启用autodocdoctest扩展名]
  2. 运行sphinx-apidoc以生成.rst文件
  3. 运行make doctest(所有测试都通过)
  4. 运行make html

我尝试在trim_doctest_flags中设置doctest_test_doctest_blocksconf.py变量没有成功。

我是否缺少触发sphinx来删除html文档的内容?我希望这是足够的信息,可以指出正确的方向,因为除了这一个问题外,文档看起来都不错。但是,如果需要,我可以提供更多详细信息或示例。

更新:MCV示例(使用Sphinx 1.8.2)目录和文件结构

.
├── trial
│   ├── __init__.py
│   └── trial.py
└── trialDocs
    ├── build
    ├── Makefile
    └── source
        ├── _static
        ├── _templates
        ├── conf.py
        ├── index.rst
        ├── modules.rst
        └── trial.rst

conf.py

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
import os
import sys
sys.path.insert(0, os.path.abspath('../../trial'))
project = 'trial'
copyright = '2019, trial'
author = 'trial'
version = ''
release = 'trial'
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.doctest',
    'sphinx.ext.napoleon',
]
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
language = None
exclude_patterns = []
pygments_style = None
html_theme = 'alabaster'
htmlhelp_basename = 'trialdoc'
latex_elements = {}
latex_documents = [(master_doc, 'trial.tex', 'trial Documentation', 'trial', 'manual'),]
man_pages = [(master_doc, 'trial', 'trial Documentation', [author], 1)]
texinfo_documents = [(master_doc, 'trial', 'trial Documentation', author, 'trial', 'One line description of project.', 'Miscellaneous'),]
epub_title = project
epub_exclude_files = ['search.html']
doctest_global_setup = """
from trial import *
"""
trim_doctest_flags=True

trial.rst-使用sphinx-apidoc生成

trial package
=============

Module contents
---------------

.. automodule:: trial
    :members:
    :undoc-members:
    :show-inheritance:

trial.py

def withBlankline():
    """
    Use blanklines in example.

    Determine if sphinx will eliminate <BLANKLINE> for html.

    Examples
    --------
    >>> withBlankline()
    <BLANKLINE>
    blanklines above and below
    <BLANKLINE>
    """
    print()
    print('blanklines above and below')
    print()

class Example():
    def __init__(self):
        pass

    def withEllipsis(self):
        """
        Use ellipsis in example.

        Determine if sphinx will eliminate # doctest: +ELLIPSIS for html.

        Examples
        --------
        >>> e = Example()
        >>> e.withEllipsis() # doctest: +ELLIPSIS
        abc...xyz
        """
        print('abcdefghijklmnopqrstuvwxyz')

使用make htmlsphinx-build -b html source buildtrial.html输出:enter image description here

python python-sphinx doctest autodoc numpydoc
1个回答
0
投票

基于@mzjn的评论,看来这是一个bug,已在Sphinx 2.2.0中修复:

我只是认为这将有助于在此处将其记录为答案。谢谢大家!

© www.soinside.com 2019 - 2024. All rights reserved.