Skip to content

Commit 80d37c4

Browse files
committed
Print output of jupyterlite build when silenced if it failed
1 parent 4f2bb48 commit 80d37c4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,29 @@ def jupyterlite_build(app: Sphinx, error):
594594
[isinstance(s, str) for s in command]
595595
), f"Expected all commands arguments to be a str, got {command}"
596596

597-
kwargs = {"cwd": app.srcdir, "check": True}
597+
kwargs = {"cwd": app.srcdir, "check": False}
598598
if app.env.config.jupyterlite_silence:
599-
kwargs["stdout"] = subprocess.DEVNULL
600-
kwargs["stderr"] = subprocess.DEVNULL
601-
subprocess.run(command, **kwargs)
599+
kwargs["stdout"] = subprocess.PIPE
600+
kwargs["stderr"] = subprocess.PIPE
601+
602+
completed_process = subprocess.run(command, **kwargs)
603+
604+
if completed_process.returncode != 0:
605+
if app.env.config.jupyterlite_silence:
606+
print(
607+
"`jupyterlite build` failed but it's output has been silenced."
608+
" stdout and stderr are reproduced below.\n"
609+
)
610+
print("stdout:", completed_process.stdout.decode())
611+
print("stderr:", completed_process.stderr.decode())
612+
613+
# Raise the original exception that would have occurred with check=True
614+
raise subprocess.CalledProcessError(
615+
returncode=completed_process.returncode,
616+
cmd=command,
617+
output=completed_process.stdout,
618+
stderr=completed_process.stderr,
619+
)
602620

603621
print("[jupyterlite-sphinx] JupyterLite build done")
604622

0 commit comments

Comments
 (0)