Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Sphinx run my code on executing 'make html'?

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 documentation 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 popping 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?

like image 691
AME Avatar asked Sep 12 '12 15:09

AME


People also ask

What does Sphinx build do?

sphinx-build can create documentation in different formats. A format is selected by specifying the builder name on the command line; it defaults to HTML. Builders can also perform other tasks related to documentation processing. For a list of available builders, refer to sphinx-build -b .


1 Answers

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.

like image 84
mzjn Avatar answered Oct 02 '22 13:10

mzjn