Debian Codegraph @

documentation/source/readthedocs.rst

raw
1
2 Running on Read the Docs
3 =========================
4
5 `Read the Docs`_ is an excellent site for hosting project documentation. It
6 provides hooks into common project hosting sites like Github_ & Bitbucket_ and can
7 rebuild your documentation automatically whenever you push new code.
8
9 The site is designed for documentation written with Sphinx and supports Sphinx
10 extensions via a correctly configured ``setup.py`` file.
11
12 As Breathe is a Sphinx extension you can use it on Read the Docs. However, as
13 Breathe requires doxygen XML files, some additional configuration is required.
14
15 Doxygen Support
16 ---------------
17
18 Read the Docs do not explicitly support doxygen however they have had
19 requests for it to be supported and it is currently installed on their build
20 servers.
21
22 Generating Doxygen XML Files
23 ----------------------------
24
25 We assume that you are not checking your doxygen XML files into your source
26 control system and so you will need to generate them on the Read the Docs
27 server before Sphinx starts processing your documentation.
28
29 One simple way of achieving this is to add the following code to your
30 ``conf.py`` file:
31
32 .. code-block:: python
33
34 import subprocess, os
35
36 read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
37
38 if read_the_docs_build:
39
40 subprocess.call('cd ../doxygen; doxygen', shell=True)
41
42 The first line uses the ``READTHEDOCS`` environment variable to determine
43 whether or not we are building on the Read the Docs servers. Read the Docs
44 set this environment variable `specifically for this purpose`_.
45
46 Then, if we are in a Read the Docs build, execute a simple shell command to
47 build the doxygen xml for your project. This is a very simple example; the
48 command will be determined by your project set up but something like this works
49 for the Breathe documentation.
50
51 As this is then executed right at the start of the ``sphinx-build`` process then
52 all your doxygen XML files will be in place for the build.
53
54 A More Involved Setup
55 ---------------------
56
57 If you'd rather do something more involved then you can run ``doxygen`` as part
58 of a ``builder-inited`` event hook which you can install from your ``conf.py``
59 file by adding a ``setup`` function as shown below.
60
61 This is an approximation of the code that Breathe has in its ``conf.py`` in
62 order to run ``doxygen`` on the Read the Docs server.
63
64 .. code-block:: python
65
66 import subprocess, sys
67
68 def run_doxygen(folder):
69 """Run the doxygen make command in the designated folder"""
70
71 try:
72 retcode = subprocess.call("cd %s; make" % folder, shell=True)
73 if retcode < 0:
74 sys.stderr.write("doxygen terminated by signal %s" % (-retcode))
75 except OSError as e:
76 sys.stderr.write("doxygen execution failed: %s" % e)
77
78
79 def generate_doxygen_xml(app):
80 """Run the doxygen make commands if we're on the ReadTheDocs server"""
81
82 read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
83
84 if read_the_docs_build:
85
86 run_doxygen("../../examples/doxygen")
87 run_doxygen("../../examples/specific")
88 run_doxygen("../../examples/tinyxml")
89
90
91 def setup(app):
92
93 # Add hook for building doxygen xml when needed
94 app.connect("builder-inited", generate_doxygen_xml)
95
96 .. _Read the Docs: https://readthedocs.org/
97 .. _Github: https://github.com
98 .. _Bitbucket: https://bitbucket.org
99 .. _specifically for this purpose: https://docs.readthedocs.org/en/latest/faq.html#how-do-i-change-behavior-for-read-the-docs