0

I am currently using sphinx to automatically generate my documentation site from ReStructuredText files within a bitbucket repo.

This is of course all managed/hosted internally but I have been thinking more and more about whether I could switch this out for a more serverless model, using FaaS to generate the site and then a cloud based site hosting for the actual hosting (e.g S3 static site hosting).

I was wondering whether it was possible to use sphinx in a programmatic way (e.g within a AWS Lambda or Azure Function)?

Thanks, John

John Bartlett
  • 370
  • 1
  • 3
  • 13
  • As someone who doesn't know very much about serverless models, AWS Lambda, Azure Function etc, I wonder what you mean by "use sphinx in a programmatic way". As opposed to "non-programmatic"? – mzjn Feb 17 '18 at 11:31
  • Perhaps bad choice of phrase, I mean call and use within code rather than from the command line. – John Bartlett Feb 17 '18 at 11:48
  • OK. Perhaps this helps: https://stackoverflow.com/a/47657926/407651 – mzjn Feb 17 '18 at 11:49
  • Thanks mzjn that did help. If you put that as the answer I will accept it? – John Bartlett Mar 11 '18 at 16:08

1 Answers1

1

Instead of executing sphinx-build from the command line, you can generate output by using a sphinx.application.Sphinx object directly.

A basic example:

import os
from sphinx.application import Sphinx

# Main arguments 
srcdir = "/path/to/source"
confdir = srcdir
builddir = os.path.join(srcdir, "_build")
doctreedir = os.path.join(builddir, "doctrees")
builder = "html"

# Create the Sphinx application object
app = Sphinx(srcdir, confdir, builddir, doctreedir, builder)

# Run the build
app.build()
mzjn
  • 48,958
  • 13
  • 128
  • 248
  • Note that this way of running a build is "unofficial". It is not described in the Sphinx documentation (the `build()` method is not part of the documented application API). – mzjn Mar 11 '18 at 17:31