OptionParser是否与Sphinx冲突? [英] Is OptionParser in conflict with sphinx?

查看:113
本文介绍了OptionParser是否与Sphinx冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在sphinx中为我的项目编写文档,并且只要sphinx在我的模块中遇到OptionParser,它就会给我:

I'm trying to write a documentation for my project in sphinx and whenever sphinx encounters OptionParser in my module it gives me:

sphinx-build: error: no such option: -b

我认为这是不可能的,所以我写了一个简单的模块来检查:

I thought that it's impossible, so I wrote a simple module to check this:

from optparse import OptionParser

"""some comment here"""

parser = OptionParser(conflict_handler='resolve')
parser.add_option('', '--force', action='store_true', dest='force', default=False, help='gqdel will skip asking questions, and delete them all.');
parser.add_option('', '--verbose', action='store_true', dest='verbose', default=False, help='Report additional information from gqdel')

(options, args) = parser.parse_args()

"""and here"""

print "foo"

它给了我同样的错误. 我的第一个样子是这样的:

And it gives me the same error. My rst looks like this:

some title
==========

.. automodule:: test
   :members:

推荐答案

这是我认为的情况:

运行Sphinx时, autodoc 会导入您的模块,并且该模块中的顶级代码为被执行.创建一个OptionParser实例,并处理传递给sphinx-build 其中之一的命令行参数和选项.是 -b .您的OptionParser不允许此选项.

When Sphinx runs, autodoc imports your module and the toplevel code in the module is executed. An OptionParser instance is created, and it processes the command line arguments and options passed to sphinx-build, one of which is -b. Your OptionParser does not allow this option.

我会将OptionParser代码放入函数中,以便在导入模块时不执行该代码.

I would put the OptionParser code in a function so that it is not executed when the module is imported.

这篇关于OptionParser是否与Sphinx冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆