Skip to content

Commit

Permalink
Run sphinx-build in a subprocess (#164)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
return42 and AA-Turner authored Sep 3, 2024
1 parent 23c16b0 commit e6101ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions sphinx_autobuild/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def main(argv=()):
"""Actual application logic."""
colorama.init()

if not argv:
# entry point functions don't receive args
argv = sys.argv[1:]

args, build_args = _parse_args(list(argv))

src_dir = args.sourcedir
Expand Down
13 changes: 4 additions & 9 deletions sphinx_autobuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import subprocess

# This isn't public API, but we want to avoid a subprocess call
from sphinx.cmd.build import build_main

from sphinx_autobuild.utils import show


Expand Down Expand Up @@ -32,12 +29,10 @@ def __call__(self, *, rebuild: bool = True):
raise

show(command=["sphinx-build"] + self.sphinx_args)

# NOTE:
# sphinx.cmd.build.build_main is not considered to be public API,
# but as this is a first-party project, we can cheat a little bit.
if return_code := build_main(self.sphinx_args):
print(f"Sphinx exited with exit code: {return_code}")
try:
subprocess.run(["sphinx-build"] + self.sphinx_args, check=True)
except subprocess.CalledProcessError as e:
print(f"Sphinx exited with exit code: {e.returncode}")
print(
"The server will continue serving the build folder, but the contents "
"being served are no longer in sync with the documentation sources. "
Expand Down

0 comments on commit e6101ff

Please sign in to comment.