This is an archive of the discontinued LLVM Phabricator instance.

[lldb][docs] Use sphinx instead of epydoc to generate LLDB's Python reference
ClosedPublic

Authored by teemperor on Jan 12 2021, 4:41 AM.

Details

Summary

Currently LLDB uses epydoc to generate the Python API reference for the website.
epydoc however is unmaintained since more than a decade and no longer works with Python 3.
Also whatever setup we had once for generating the documentation on the website server
no longer seems to work, so the current website documentation has been stale since more than a year.

This patch replaces epydoc with sphinx and its automodapi plugin that can generate Python
API references. LLVM already uses sphinx for the rest of the documentation, so this way
we are more consistent with the rest of LLVM. The only new dependency is the automodapi plugin for sphinx.

This patch effectively does the following things:

  • Remove the epydoc code.
  • Make a new dummy Python API page in our website that just calls the Sphinx command for generated the API documentation.
  • Add a mock _lldb module that is only used when generating the Python API. This way we don't have to build all of LLDB to generate the API reference.

Some notes:

  • The long list of skips is necessary due to boilerplate functions that SWIG is generating. Sadly automodapi is not really scriptable from what I can see, so we have to blacklist this stuff manually.
  • The .gitignore change because automodapi wants a subfolder of our documentation directory to place generated documentation files there. The path is also what is used on the website, so we can't really workaround this (without copying the whole docs dir somewhere else when we build).
  • We have to use environment variables to pass our build path to our sphinx configuration. Sphinx doesn't support passing variables onto that script.

Diff Detail

Event Timeline

teemperor created this revision.Jan 12 2021, 4:41 AM
teemperor requested review of this revision.Jan 12 2021, 4:41 AM

I generated the current website here: https://teemperor.de/pub/sbapi/

Note that the old website used ASCII art to style the documentation, so all this formatting is broken there until we replace it with restructured text formatting.

teemperor updated this revision to Diff 316064.Jan 12 2021, 4:51 AM
  • Use the old output directory name.
JDevlieghere added inline comments.Jan 12 2021, 9:14 AM
.gitignore
67

Any way we can make sure this ends up in the build dir instead?

lldb/docs/python_api/conf.py
1 ↗(On Diff #316064)

Why a separate configuration/website and not include this in the existing Sphinx configuration?

teemperor added inline comments.Jan 12 2021, 10:04 AM
.gitignore
67

I could ask CMake to give us a relative path to some build subdir (apparently the sphinx plugin wants a relative path for some reason). But doing a relative path from source to build can end up causing some sketchy results (like, you can't do cross-drive relative paths on Windows and not sure what other weird situations can have non-functioning relative paths). We could also just see if we can sneak in an absolute path and maybe the sphinx plugin doesn't complain.

lldb/docs/python_api/conf.py
1 ↗(On Diff #316064)

Just because that you can still generate a separate Python API (like, if we want to make one for downstream LLDB). Also I believe the themes are different for LLDB's website and the Python API (I'm using the LLVM theme in the Python API, but the LLDB website is using its own theme). Not sure if there is a way to make parts of a sphinx page a different theme.

JDevlieghere added inline comments.
lldb/docs/python_api/conf.py
1 ↗(On Diff #316064)

For cross referencing it would be much nicer if this was single instance. I don't think the first issue should be a concern as long as the pages are generated in their own directory. The theme being different also sounds like a bug rather than a feature to me. When I originally did the Sphinx migration I went with the LLVM/Clang theme and the main objections was the lack of the sidebar. @aprantl and I hacked up the CSS of the alabaster theme to make it look like the old website, but maybe it's time to reconsider that.

JDevlieghere added inline comments.Jan 12 2021, 10:39 AM
.gitignore
67

Understood. Seems like it's not worth the hassle.

teemperor updated this revision to Diff 316346.Jan 13 2021, 1:31 AM
  • Merged Python API and normal website.
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2021, 1:31 AM

I merged the Python API now into the normal website (see https://teemperor.de/pub/lldb_website/python_api.html# for how this looks). So cross-referencing and the website search now work for everything.

The Python API will now just use the normal LLDB website theme and that looks actually pretty nice and seems consistent with the rest of the LLVM project's websites. It's not consistent with the way Clang and LLVM's *documentation pages* look, but those are also not consistent with the website look&feel.

I also moved the environment passing to LLVM's Sphinx CMake code (because otherwise we can't reuse all their boilerplate as we did before).

.gitignore
67

So I tired to see what will happen with an absolute path (or a generated relative path), but it seems that 'relative path' here is actually both the URL on the final website and the path to the directory, i.e., lldb.llvm.org/WHATEVER_PATH_WE_PASS/lldb.SBAddress.html. It seems the plugin just throws some generated rst files in a subdirectory and Sphinx is doing the rest).

teemperor edited the summary of this revision. (Show Details)Jan 13 2021, 1:54 AM
JDevlieghere accepted this revision.Jan 14 2021, 10:03 AM

LGTM. Thanks for driving this!

This revision is now accepted and ready to land.Jan 14 2021, 10:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2021, 4:27 AM
tschuett added a subscriber: tschuett.EditedJan 17 2021, 6:41 AM

There is no syntax highlighting for Python in sphinx? The code in
https://lldb.llvm.org/python_api/lldb.SBDebugger.html#lldb.SBDebugger
is hard to read.

Even the line breaks between the source code and web page differ.

There is no syntax highlighting for Python in sphinx? The code in
https://lldb.llvm.org/python_api/lldb.SBDebugger.html#lldb.SBDebugger
is hard to read.

Even the line breaks between the source code and web page differ.

There is, but someone (probably me) needs to rewrite and update all the documentation in restructured text so that sphinx knows this is a code example (previously we had just plaintext). Currently working on all that.

There is no syntax highlighting for Python in sphinx? The code in
https://lldb.llvm.org/python_api/lldb.SBDebugger.html#lldb.SBDebugger
is hard to read.

Even the line breaks between the source code and web page differ.

There is, but someone (probably me) needs to rewrite and update all the documentation in restructured text so that sphinx knows this is a code example (previously we had just plaintext). Currently working on all that.

Thanks!