我无法消除html输出的doctest标志(即<BLANKLINE>
,# doctest: +ELLIPSIS
)。我能够生成所需的文档,因此没有错误,但其中包含我要删除的这些标记。 Sphinx文档here声称这是可能的,所以我必须做错了什么。我的文档示例为numpy样式,并且我尝试同时使用napoleon和numpydoc扩展名。
这是我已采取的步骤。
sphinx-quickstart
(启用autodoc
和doctest
扩展名)sphinx-apidoc
来生成.rst文件make doctest
(所有测试均通过)make html
我尝试在trim_doctest_flags
中设置doctest_test_doctest_blocks
和conf.py
变量,但没有成功。
我是否缺少某些东西来触发狮身人面像以删除这些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')
答案 0 :(得分:0)
根据@mzjn的评论,看来这是一个漏洞,已在Sphinx 2.2.0中修复:
问题:doctest comments not getting trimmed since Sphinx 1.8.0 - Issue #6545