Skip to content

Commit 230ba7c

Browse files
Merge pull request #225 from agriyakhetarpal/feat/allow-configuring-overrides-file
Allow the use of a custom `overrides.json` file for configuring JupyterLite at runtime
2 parents 4096adb + b7e6bb6 commit 230ba7c

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

docs/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
jupyterlite_bind_ipynb_suffix = False
1414
strip_tagged_cells = True
1515

16+
# Enable this to use the provided sample overrides JSON file.
17+
# jupyterlite_overrides = "sample_overrides.json"
18+
19+
# Enable this to unsilence JupyterLite and aid debugging
20+
# within our own documentation.
21+
# jupyterlite_silence = False
22+
1623
master_doc = "index"
1724

1825
# General information about the project.

docs/configuration.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,27 @@ dependencies:
4444
- ipycanvas
4545
```
4646
47-
## JupyterLite config
47+
## JupyterLite configuration
4848
49-
You can provide [custom configuration](https://jupyterlite.readthedocs.io/en/latest/howto/index.html#configuring-a-jupyterlite-deployment)
50-
to your JupyterLite deployment.
49+
You can provide [custom configuration files](https://jupyterlite.readthedocs.io/en/stable/howto/configure/config_files.html)
50+
to your JupyterLite deployment for build-time configuration and settings overrides.
51+
52+
The build-time configuration can be used to change the default settings for JupyterLite, such
53+
as changing which assets are included, the locations of the assets, which plugins are enabled,
54+
and more.
55+
56+
The runtime configuration can be used to change the settings of the JupyterLite deployment
57+
after it has been built, such as changing the theme, the default kernel, the default language,
58+
and more.
59+
60+
<!-- TODO: Run-time configuration via `jupyter-lite.json` not added yet here
61+
because I can't yet find a direct jupyter lite CLI mapping for that option -->
5162

5263
```python
53-
jupyterlite_config = "jupyterlite_config.json"
64+
# Build-time configuration for JupyterLite
65+
jupyterlite_config = "jupyter_lite_config.json"
66+
# Override plugins and extension settings
67+
jupyterlite_overrides = "overrides.json"
5468
```
5569

5670
## Strip particular tagged cells from IPython Notebooks

docs/sample_overrides.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"@jupyterlab/notebook-extension:panel": {
3+
"toolbar": [
4+
{
5+
"name": "download",
6+
"label": "Download",
7+
"args": {},
8+
"command": "docmanager:download",
9+
"icon": "ui-components:download",
10+
"rank": 50
11+
}
12+
]
13+
},
14+
"@jupyterlab/apputils-extension:themes": {
15+
"theme": "JupyterLab Christmas"
16+
},
17+
"@jupyter-notebook/application-extension:top": {
18+
"visible": "no"
19+
}
20+
}

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)