I've seen several functionalities in Sphinx that define a setup(app) function, for example the "Docstring preprocessing" functionalities of the autodoc extension.
I tried finding the API for setup(app) but the results haven't fully enlightened me. I found this brief explanation:
Each Sphinx extension is a Python module with at least a setup() function. This function is called at initialization time with one argument, the application object representing the Sphinx process.
There is also this explanation:
Developing extensions for Sphinx
When
sphinx-buildis executed, Sphinx will attempt to import each module that is listed, and executeyourmodule.setup(app). This function is used to prepare the extension (e.g., by executing Python code), linking resources that Sphinx uses in the build process (like CSS or HTML files), and notifying Sphinx of everything the extension offers (such as directive or role definitions). Theappargument is an instance of Sphinx and gives you control over most aspects of the Sphinx build.
And finally this explanation:
These events are known to the core. The arguments shown are given to the registered event handlers. Use
Sphinx.connect()in an extension’ssetupfunction (note thatconf.pycan also have a setup function) to connect handlers to the events.
So my question is if the only use of setup(app) in conf.py is connecting event handlers to Sphinx core events through Sphinx.connect(event, callback) function? Or am I missing something? Are all other uses of setup(app) restricted to writing custom extensions?
P.S. Adding confusion the setup reserved word is also used by "Setuptools integration", and searching the documentation there are several occurrences . I suppose this is an unrelated coincidence of using the same name.