Skip to content

Commit af6ec92

Browse files
committed
[lldb] Cleanup Python API reference files after building the docs
The sphinx-automodapi extension requires that the generated RST files live next to the index file. This means that we generate them in the source directory rather than the build directory. This patch ensures these files are removed again when sphinx finishes its build. The proper solution to this problem would be to move everything in the doc folder from the source directory to the build directory before generating the docs. I believe that old RST files being kept around is the reason that the Python API references on the website isn't getting updated. This patch is meant as a speculative fix and a way to confirm that.
1 parent 2a28861 commit af6ec92

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lldb/docs/conf.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# serve to show the default.
1313
from __future__ import print_function
1414

15-
import sys, os, re
15+
import sys, os, re, shutil
1616
from datetime import date
1717

1818
building_man_page = tags.has('builder-man')
@@ -293,8 +293,8 @@
293293
empty_attr_summary = re.compile(r'\.\. rubric:: Attributes Summary\s*\.\. autosummary::\s*\.\. rubric::')
294294
empty_attr_documentation = re.compile(r'\.\. rubric:: Attributes Documentation\s*\.\. rubric::')
295295

296-
def cleanup_source(app, docname, source):
297-
""" Cleans up source files generated by automodapi. """
296+
def preprocess_source(app, docname, source):
297+
""" Preprocesses source files generated by automodapi. """
298298
# Don't cleanup anything beside automodapi-generated sources.
299299
if not automodapi_toctreedirnm in docname:
300300
return
@@ -320,5 +320,12 @@ def cleanup_source(app, docname, source):
320320
# element list).
321321
source[0] = processed
322322

323+
def cleanup_source(app, exception):
324+
""" Remove files generated by automodapi in the source tree. """
325+
if hasattr(app.config, 'automodapi_toctreedirnm'):
326+
api_source_dir = os.path.join(app.srcdir, app.config.automodapi_toctreedirnm)
327+
shutil.rmtree(api_source_dir, ignore_errors=True)
328+
323329
def setup(app):
324-
app.connect('source-read', cleanup_source)
330+
app.connect('source-read', preprocess_source)
331+
app.connect('build-finished', cleanup_source)

0 commit comments

Comments
 (0)