Skip to content

Commit 2e55d46

Browse files
Allow jupyterlite_overrides configuration option
1 parent 4096adb commit 2e55d46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ def jupyterlite_build(app: Sphinx, error):
743743
if app.builder.format == "html":
744744
print("[jupyterlite-sphinx] Running JupyterLite build")
745745
jupyterlite_config = app.env.config.jupyterlite_config
746+
jupyterlite_overrides = app.env.config.jupyterlite_overrides
746747
jupyterlite_contents = app.env.config.jupyterlite_contents
747748

748749
jupyterlite_dir = str(app.env.config.jupyterlite_dir)
@@ -752,9 +753,24 @@ def jupyterlite_build(app: Sphinx, error):
752753
)
753754

754755
config = []
756+
overrides = []
755757
if jupyterlite_config:
756758
config = ["--config", jupyterlite_config]
757759

760+
if jupyterlite_overrides:
761+
# JupyterLite's build command does not validate the existence
762+
# of the JSON file, so we do it ourselves.
763+
# We will raise a FileNotFoundError if the file does not exist
764+
# in the Sphinx project directory.
765+
overrides_path = Path(app.srcdir) / jupyterlite_overrides
766+
if not Path(overrides_path).exists():
767+
raise FileNotFoundError(
768+
f"Overrides file {overrides_path} does not exist. "
769+
"Please check your configuration."
770+
)
771+
772+
overrides = ["--settings-overrides", jupyterlite_overrides]
773+
758774
if jupyterlite_contents is None:
759775
jupyterlite_contents = []
760776
elif isinstance(jupyterlite_contents, str):
@@ -783,6 +799,7 @@ def jupyterlite_build(app: Sphinx, error):
783799
"build",
784800
"--debug",
785801
*config,
802+
*overrides,
786803
*contents,
787804
"--contents",
788805
os.path.join(app.srcdir, CONTENT_DIR),
@@ -859,6 +876,7 @@ def setup(app):
859876

860877
# Config options
861878
app.add_config_value("jupyterlite_config", None, rebuild="html")
879+
app.add_config_value("jupyterlite_overrides", None, rebuild="html")
862880
app.add_config_value("jupyterlite_dir", str(app.srcdir), rebuild="html")
863881
app.add_config_value("jupyterlite_contents", None, rebuild="html")
864882
app.add_config_value("jupyterlite_bind_ipynb_suffix", True, rebuild="html")

0 commit comments

Comments
 (0)