我正在尝试学习Docker。
我有一个使用mod库的Python脚本,该脚本不是安装在我的系统上。目标是在Docker容器中执行它。我写了Dockerfile。我在其中添加了这一行:
RUN pip install --trusted-host pypi.python.org -r requirements.txt
然后在Requirements.txt中,我写了 mod 。
它起作用了,并且在容器内部安装了mod,并且代码运行良好。
现在,我想在同一脚本上生成Sphinx文档。我知道Sphinx的工作原理(基本知识)。我用conf.py
修改了sys.path.insert(0, os.path.abspath('..'))
,它指向包含Script.py的目录(与Dockerfile和requirements.txt并存),然后在index.rst内添加了以下内容:Script.py位于文件夹内名为DockerPython:
.. automodule:: DockerPython.Script
:members:
启动make html
(与其他示例配合使用)时,我得到以下信息:
Running Sphinx v2.0.1
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index
WARNING: autodoc: failed to import module 'Script' from module 'DockerPython'; the following exception was raised:
No module named 'mod'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 1 warning.
The HTML pages are in build\html.
我得到的页面是空的。
所以,我的问题是:Sphinx能否在无法编译且无法在本地Python上良好运行的脚本上执行(因为没有在本地安装lib)?
如何使它在通过Docker具有特定设置的脚本上工作?谢谢。
答案 0 :(得分:0)
经过两个小时的冲浪,我才发现。
我只需要将此行添加到conf.py
:
autodoc_mock_imports = ['mod']