2015-05-12 96 views
0

我有以下目录结构。没有为包中的所有python模块生成模块文档

$ tree emaildiff/ 
|____ 
| |______init__.py 
| |______init__.pyc 
| |____mail 
| | |____.DS_Store 
| | |______init__.py 
| | |______init__.pyc 
| | |____send.py 
| | |____send.pyc 
| |____maildiff_cmd.py 
| |____maildiff_cmd.pyc 
| |____version.py 
| |____version.pyc 

,我有两页代码maildiff和发送

$ tree docs/source/ 
| |____ 
| | |_____static 
| | |_____templates 
| | |____conf.py 
| | |____index.rst 
| | |____maildiff.rst 
| | |____send.rst 
| | |____terminal.glue 

基础上,

我有什么

.. automodule:: maildiff_cmd 
    :members: 
    :undoc-members: 
    :inherited-members: 
    :show-inheritance: 

和send.py

.. automodule:: send 
    :members: 
    :undoc-members: 
    :inherited-members: 
    :show-inheritance: 

,并在conf.py,而这样做使我的HTML插入了Python模块路径

sys.path.insert(0, os.path.abspath('../../emaildiff')) 

,但我仍然得到错误

==================================== 
/Development/pyclones/git-maildiff/docs/source/maildiff.rst:13: WARNING: autodoc: failed to import module u'maildiff_cmd'; the following exception was raised: 
Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object 
    __import__(self.modname) 
    File "/Development/pyclones/git-maildiff/emaildiff/maildiff_cmd.py", line 14, in <module> 
    import emaildiff.mail.send as send 
ImportError: No module named emaildiff.mail.send 
/Development/pyclones/git-maildiff/docs/source/send.rst:7: WARNING: Title underline too short. 

第二个错误如下:

Welcome to maildiff git command documentation! 
==================================== 
/Development/pyclones/git-maildiff/docs/source/send.rst:13: WARNING: autodoc: failed to import module u'send'; the following exception was raised: 
Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object 
    __import__(self.modname) 
ImportError: No module named send 

所以如果我包括

sys.path.insert(1, os.path.abspath('../../emaildiff/mail')) 

第二个错误消失,为send.py生成文档,但emaildiff/mailddiff_cmd.py永远不会生成。

+0

不应该认为是'sys.path.insert(1,os.path.abspath则( '../../'))' – cwallenpoole

回答

0

我得到它的工作,

我必须包括要明确地插入,即使我有实际的模块旁边__init__.py文件选址模块位置路径的每一个。

sys.path.insert(0, os.path.abspath('../../')) 
sys.path.insert(1, os.path.abspath('../../emaildiff')) 
sys.path.insert(2, os.path.abspath('../../emaildiff/mail')) 
+0

它好像的顺序路径被插入是重要。因此,如果有人在使用'sys.path.append'而不是'sys.path.insert'来改变这一点。它绊倒了我很多。 – salomonvh

相关问题