sphinx是否运行我的代码执行'make html'? [英] Does sphinx run my code on executing 'make html'?

查看:365
本文介绍了sphinx是否运行我的代码执行'make html'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个相当大的代码库,我想为其创建html文档。由于它是用Python编写的,我决定使用sphinx,因为代码的用户习惯了使用sphinx创建的python-documention的设计和功能。
我使用命令 sphinx-apidoc 来自动创建第一个文件。我将模块路径导入到 sys.path 中,以便sphinx可以找到代码。



到目前为止这么好。但是,当我尝试使用命令 make html 创建html时,有很多追溯回溯,代码库中的一些示例似乎被执行。什么可能是原因,如何防止这种情况发生?

解决方案

使用 autodoc ,Sphinx导入已记录的模块,因此执行所有模块级代码。每当你做make html时,都会发生这种情况。在这个意义上,Sphinx确实运行你的代码。



您可能需要组织您的代码,使错误消失(将模块级代码移动到函数)。有关可能发生的情况,请参见此问题



这是我的猜测,但可能不是全部的故事。没有额外的信息很难说更多。


I inherited a rather large codebase that I want to create html-documentation for. Since it is written in Python I decided to use sphinx because the users of the code are accustomed to the design and functionality of the python-documention that's created with sphinx. I used the command sphinx-apidoc to automatically create the rst-files. I imported the module path into sys.path so that sphinx can find the code.

So far so good. However, when I try to create the html using the command make html, there are many tracebacks poping up and some of the examples in the codebase seem to get executed. What can be the reason for that and how can I prevent that from happening?

解决方案

When using autodoc, Sphinx imports the documented modules, so all module-level code is executed. This happens every time you do "make html". In that sense, Sphinx does "run" your code.

You may have to organize your code a bit differently to make the errors go away (move module-level code to functions). See this question for an example of what can happen.

This is my guess but it may not be the whole story. It's hard to say more without additional information.

这篇关于sphinx是否运行我的代码执行'make html'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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