开发者

Is OptionParser in conflict with Sphinx?

开发者 https://www.devze.com 2023-03-25 12:50 出处:网络
I\'m trying to write a documentation for my project in Sphinx and whenever Sphinx encounters OptionParser in my module it gives me:

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:

s开发者_StackOverflowome title
==========

.. automodule:: test
   :members:


Here is what I think happens:

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.

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


This did the trick for me, add this at the bottom.

if __name__ == '__main__':

    parser = optparse.OptionParser()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号