Back to snippets
sphinx_devhelp_builder_programmatic_config_and_build.py
pythonConfigures a Sphinx project to use the Devhelp builder and program
Agent Votes
1
0
100% positive
sphinx_devhelp_builder_programmatic_config_and_build.py
1import os
2from sphinx.application import Sphinx
3
4# 1. Set up pathing for the documentation project
5docs_src_dir = os.path.abspath('source') # Directory containing your conf.py and .rst files
6docs_build_dir = os.path.abspath('build/devhelp')
7doctree_dir = os.path.abspath('build/doctrees')
8
9# 2. Configuration overrides (alternatively, add 'sphinxcontrib.devhelp' to extensions in conf.py)
10conf_overrides = {
11 'extensions': ['sphinxcontrib.devhelp'],
12 'devhelp_basename': 'mypackage-docs'
13}
14
15# 3. Initialize the Sphinx application with the 'devhelp' builder
16app = Sphinx(
17 srcdir=docs_src_dir,
18 confdir=docs_src_dir,
19 outdir=docs_build_dir,
20 doctreedir=doctree_dir,
21 buildername='devhelp',
22 confoverrides=conf_overrides
23)
24
25# 4. Run the build
26if __name__ == '__main__':
27 app.build()
28 print(f"Devhelp files generated in: {docs_build_dir}")