Skip to content

Commit

Permalink
Refactor terminal messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Feb 4, 2024
1 parent 826bc2a commit 0ffc86f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sphinx_autobuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ def _log(text, *, colour):


def show(*, context=None, command=None):
"""Show context and command-to-be-executed, with nice formatting and colors."""
"""Show context and command-to-be-executed, with nice formatting and colours."""
if context is not None:
_log(context, colour=Fore.CYAN)
if command is not None:
assert isinstance(command, (list, tuple))
_log("> " + shlex.join(command), colour=Fore.BLUE)
msg = f"> {shlex.join(command)}"
_log(msg, colour=Fore.BLUE)


def get_builder(watcher, sphinx_args, *, host, port, pre_build_commands):
Expand All @@ -67,13 +68,7 @@ def build():
show(command=["sphinx-build"] + sphinx_args)
subprocess.run(sphinx_command, check=True)
except subprocess.CalledProcessError as e:
print(f"Command 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. "
"Please fix the cause of the error above or press Ctrl+C to stop the "
"server."
)
cmd_exit(e.returncode)
finally:
# We present this information, so that the user does not need to keep track
# of the port being used. It is presented by livereload when starting the
Expand All @@ -82,3 +77,13 @@ def build():
show(context=f"Serving on http://{host}:{port}")

return build


def cmd_exit(return_code):
print(f"Command exited with exit code: {return_code}")
print(
"The server will continue serving the build folder, but the contents "
"being served are no longer in sync with the documentation sources. "
"Please fix the cause of the error above or press Ctrl+C to stop the "
"server."
)

0 comments on commit 0ffc86f

Please sign in to comment.