From e6101ff68017af7c6733a8061b49fd556b75e0c1 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 3 Sep 2024 08:46:23 +0200 Subject: [PATCH] Run `sphinx-build` in a subprocess (#164) Signed-off-by: Markus Heiser Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- sphinx_autobuild/__main__.py | 4 ++++ sphinx_autobuild/build.py | 13 ++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/sphinx_autobuild/__main__.py b/sphinx_autobuild/__main__.py index c63ddae..63a01be 100644 --- a/sphinx_autobuild/__main__.py +++ b/sphinx_autobuild/__main__.py @@ -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 diff --git a/sphinx_autobuild/build.py b/sphinx_autobuild/build.py index 0859dc3..2c0adc4 100644 --- a/sphinx_autobuild/build.py +++ b/sphinx_autobuild/build.py @@ -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 @@ -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. "