Does sphinx execute my code when doing 'make html'?

I have inherited a fairly large code base for which I want to create html documentation. Since it is written in Python, I decided to use sphinx because users of the code are used to the design and functionality of python-documention created using sphinx. I used the sphinx-apidoc to automatically create the first files. I imported the module path into sys.path so that the sphinx can find the code.

So far so good. However, when I try to create html using the make html , a lot of traces appear, and some of the codebase examples seem to run. What could be causing this and how can I prevent this?

+6
source share
2 answers

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

You may need to sort your code a bit so that the errors disappear (translate the module code into functions). See this question for an example of what might happen.

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

+8
source
 def main(): print('hello world') if __name__ == '__main__': main() 

This way your code will not run.

0
source

Source: https://habr.com/ru/post/925232/


All Articles