Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have sphinx call a script or executable as a pre build task?

I'm trying to stitch together doxygen and sphinx using breathe.

breathe requires you generate doxygen xml output first though: https://breathe.readthedocs.io/en/latest/quickstart.html

I don't want to do this in a separate step. Can I just have sphinx-build execute doxygen for me on build? I just need it to run this command first with some args. Is this possible without having to write a custom sphinx plugin?

EDIT

This works

# Need to sleep because sometimes doxygen doesnt finish writing files before sphinx runs 
cwd = os.path.dirname(os.path.realpath(__file__))
os.system('doxygen')
time.sleep(3)
like image 424
red888 Avatar asked Oct 17 '25 21:10

red888


1 Answers

Sure, Sphinx will execute whatever Python code you add to its configuration file conf.py before it starts the documentation build process.

From the Sphinx documentation:

The configuration file is executed as Python code at build time (using importlib.import_module(), and with the current directory set to its containing directory), and therefore can execute arbitrarily complex code. Sphinx then reads simple names from the file’s namespace as its configuration.

Which means pre-build tasks can simply be implemented by running the external program, such as Doxygen in your case, as a subprocess anywhere in conf.py.

like image 155
john-hen Avatar answered Oct 19 '25 11:10

john-hen