Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Sphinx from executing the module

I am trying to do python documentation generation with Sphinx. The problem is that sphinx-build ends up executing the module/evaluating anything in global scope. Is there a reason it does this? And does anyone know of a flag that can be set to disable this?

It seems like Sphinx is trying to do code-coverage or something equivalent, which is definitely not what I want it doing. Normally this wouldn't be an issue, but a particular set of modules are very specific to an environment.

like image 262
djp Avatar asked Jun 13 '12 00:06

djp


1 Answers

Sphinx evaluates everything in the global scope because the autodoc plugin imports modules, and importing a module evaluates everything in the global scope.

To stop this, either:

  • Disable the autodoc plugin (search for autodoc in the sphinx config file), or
  • Guard the code you don't want executed with something like if __name__ == "__main__": do_stuff()
like image 121
David Wolever Avatar answered Sep 26 '22 02:09

David Wolever