Skip to content

Commit 1e80dd1

Browse files
authored
Merge pull request #153 from steppi/fix-bad-release-with-hack
Give a pragmatic solution to suppressing noisy output
2 parents 3bcf6bc + 963c4cf commit 1e80dd1

File tree

2 files changed

+45
-53
lines changed

2 files changed

+45
-53
lines changed

docs/configuration.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,14 @@ You can disable this behavior by setting the following config:
6464
jupyterlite_bind_ipynb_suffix = False
6565
```
6666

67+
### Suppressing jupyterlite logging
6768

68-
## Build logging levels
69+
`jupyterlite` can produce large amounts of output to the terminal when docs are building.
70+
By default, this output is silenced, but will still be printed if the invocation of
71+
`jupyterlite build` fails. To unsilence this output, set
6972

70-
Jupyterlite-sphinx exposes jupyterlite debug and logging flags thought the
71-
following configuration options.
72-
73-
74-
- `jupyterlite_debug`, boolean (`False`|`True`), passes the `--debug` flag to
75-
`jupyterlite build`
76-
77-
It also has the following configuration options:
78-
79-
- `jupyterlite_log_level`, a `str` (defaults to `"WARN"`) or `None`
80-
- `jupyterlite_verbosity`, a `str` (defaults to `"0"`) or `None`
81-
- `jupyterlite_reporter`, a `str` (defaults to `"zero"`) or `None`
82-
83-
Jupyterlite-sphinx uses low verbosity by default. Setting these parameters to `None` restores the `jupyterlite build` defaults.
73+
```python
74+
jupyterlite_silence = False
75+
```
8476

85-
See the `jupyterlite build` documentation for info on `log-level`. `verbosity` and `reporter` control the configuration
86-
of [doit](https://smarie.github.io/python-doit-api/api_reference/), which is used internally in `jupyterlite`.
77+
in your Sphinx `conf.py`.

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,6 @@ def jupyterlite_build(app: Sphinx, error):
548548

549549
jupyterlite_dir = str(app.env.config.jupyterlite_dir)
550550

551-
jupyterlite_debug = app.env.config.jupyterlite_debug
552-
jupyterlite_log_level = app.env.config.jupyterlite_log_level
553-
jupyterlite_verbosity = app.env.config.jupyterlite_verbosity
554-
jupyterlite_reporter = app.env.config.jupyterlite_reporter
555-
556551
config = []
557552
if jupyterlite_config:
558553
config = ["--config", jupyterlite_config]
@@ -580,37 +575,48 @@ def jupyterlite_build(app: Sphinx, error):
580575
apps_option.extend(["--apps", "voici"])
581576

582577
command = [
583-
c
584-
for c in (
585-
"jupyter",
586-
"lite",
587-
"doit" "build",
588-
"--debug" if jupyterlite_debug else None,
589-
*config,
590-
*contents,
591-
"--contents",
592-
os.path.join(app.srcdir, CONTENT_DIR),
593-
"--output-dir",
594-
os.path.join(app.outdir, JUPYTERLITE_DIR),
595-
*apps_option,
596-
"--lite-dir",
597-
jupyterlite_dir,
598-
"--log-level" if jupyterlite_log_level is not None else None,
599-
jupyterlite_log_level,
600-
"--",
601-
"--verbosity" if jupyterlite_verbosity else None,
602-
jupyterlite_verbosity,
603-
"--reporter" if jupyterlite_reporter else None,
604-
jupyterlite_reporter,
605-
)
606-
if c is not None
578+
"jupyter",
579+
"lite",
580+
"build",
581+
"--debug",
582+
*config,
583+
*contents,
584+
"--contents",
585+
os.path.join(app.srcdir, CONTENT_DIR),
586+
"--output-dir",
587+
os.path.join(app.outdir, JUPYTERLITE_DIR),
588+
*apps_option,
589+
"--lite-dir",
590+
jupyterlite_dir,
607591
]
608592

609593
assert all(
610594
[isinstance(s, str) for s in command]
611595
), f"Expected all commands arguments to be a str, got {command}"
612596

613-
subprocess.run(command, cwd=app.srcdir, check=True)
597+
kwargs = {"cwd": app.srcdir, "check": False}
598+
if app.env.config.jupyterlite_silence:
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+
)
614620

615621
print("[jupyterlite-sphinx] JupyterLite build done")
616622

@@ -635,12 +641,7 @@ def setup(app):
635641
app.add_config_value("jupyterlite_dir", str(app.srcdir), rebuild="html")
636642
app.add_config_value("jupyterlite_contents", None, rebuild="html")
637643
app.add_config_value("jupyterlite_bind_ipynb_suffix", True, rebuild="html")
638-
639-
# JLite debug configuration options
640-
app.add_config_value("jupyterlite_debug", False, rebuild="html")
641-
app.add_config_value("jupyterlite_log_level", "WARN", rebuild="html")
642-
app.add_config_value("jupyterlite_verbosity", "0", rebuild="html")
643-
app.add_config_value("jupyterlite_reporter", "zero", rebuild="html")
644+
app.add_config_value("jupyterlite_silence", True, rebuild=True)
644645

645646
app.add_config_value("global_enable_try_examples", default=False, rebuild=True)
646647
app.add_config_value("try_examples_global_theme", default=None, rebuild=True)

0 commit comments

Comments
 (0)