我试图用Python记录一个包.目前我有以下目录结构:
.
??? project
??? _build
? ??? doctrees
? ??? html
? ??? _sources
? ??? _static
??? conf.py
??? index.rst
??? __init__.py
??? make.bat
??? Makefile
??? mod1
? ??? foo.py
? ??? __init__.py
??? mod2
? ??? bar.py
? ??? __init__.py
??? _static
??? _templates
Run Code Online (Sandbox Code Playgroud)
这棵树是射击的结果sphinx-quickstart
.在conf.py
我没有注释sys.path.insert(0, os.path.abspath('.'))
,我有extensions = ['sphinx.ext.autodoc']
.
我index.rst
是:
.. FooBar documentation master file, created by
sphinx-quickstart on Thu Aug 28 14:22:57 2014.
You can adapt …
Run Code Online (Sandbox Code Playgroud) 我尝试使用 Sphinx 来记录我的代码。但我看到错误:
模块执行模块级语句,它可能会调用 sys.exit()。
我发现这个错误与代码有关:
import argparse
# parse command line arguments
parser = argparse.ArgumentParser(description='AWS VPN status checker.')
parser.add_argument('account', type=str, help='AWS account name.')
parser.add_argument('region', type=str, help='region of VPN tunnel.')
parser.add_argument('ipaddress', type=str, help='Tunnel IP address.')
parser.add_argument("-d", "--debug", help="debug", action="store_true")
args = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)
我认为这与导入模块时的“副作用”有关。
为什么不好,我该如何解决?
我继承了一个相当大的代码库,我想为它创建html文档.由于它是用Python编写的,所以我决定使用sphinx,因为代码的用户习惯于使用sphinx创建的python文档的设计和功能.我使用该命令sphinx-apidoc
自动创建rst文件.我导入了模块路径,sys.path
以便sphinx可以找到代码.
到现在为止还挺好.但是,当我尝试使用该命令创建html时make html
,会弹出许多回溯,并且代码库中的一些示例似乎已被执行.可能是什么原因以及如何防止这种情况发生?