Skip to content

Commit 944ccf4

Browse files
Add jupyterlite_contents config (#24)
* Add jupyterlite_contents config * Add docs for jupyterlite_content and jupyterlite_dir * Add contents to docs * Linter * Fix jupyterlite_contents * Fix notebook * Allow for passing contents as a string * Update docs/conf.py Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com> * Fix variable shadowing * Update src/jupyterlite_sphinx.py Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com> * Update links to wheels Co-authored-by: Jason Grout <jasongrout@users.noreply.github.com>
1 parent 0223c17 commit 944ccf4

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-4
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
html_logo = "_static/icon.svg"
99

1010
jupyterlite_config = "jupyterlite_config.json"
11+
jupyterlite_contents = "./custom_contents"
1112

1213
master_doc = 'index'
1314

docs/configuration.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
Configuration
22
=============
33

4+
JupyterLite-sphinx can be configured in your ``conf.py`` file by setting some global Python variables:
5+
6+
JupyterLite content
7+
-------------------
8+
9+
You can embed custom content (notebooks and data files) in your JupyterLite build by providing the following config:
10+
11+
.. code-block:: python
12+
13+
jupyterlite_contents = ["./path/to/my/notebooks/", "my_other_notebook.ipynb"]
14+
15+
JupyterLite dir
16+
---------------
17+
18+
By default, jupyterlite-sphinx runs the ``jupyter lite build`` command in a temporary directory, you can overwrite this behavior and ask jupyterlite to build in a given directory:
19+
20+
.. code-block:: python
21+
22+
# Build in the current directory
23+
jupyterlite_dir = "."
24+
25+
This allows for jupyterlite to automatically pick-up some paths https://jupyterlite.readthedocs.io/en/latest/reference/cli.html#the-lite-dir
26+
27+
JupyterLite config
28+
------------------
29+
430
You can provide `custom configuration <https://jupyterlite.readthedocs.io/en/latest/configuring.html>`_ to your JupyterLite deployment.
531

632
For example, if you want to have bqplot working in this deployment, you need to install the bqplot federated extension

docs/custom_contents/data.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
A,B,C,D
2+
1,2,3,4
3+
7,8,9,10
4+
32,45,90,54
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"name": "python",
5+
"display_name": "Pyolite",
6+
"language": "python"
7+
},
8+
"language_info": {
9+
"codemirror_mode": {
10+
"name": "python",
11+
"version": 3
12+
},
13+
"file_extension": ".py",
14+
"mimetype": "text/x-python",
15+
"name": "python",
16+
"nbconvert_exporter": "python",
17+
"pygments_lexer": "ipython3",
18+
"version": "3.8"
19+
}
20+
},
21+
"nbformat_minor": 5,
22+
"nbformat": 4,
23+
"cells": [
24+
{
25+
"cell_type": "code",
26+
"source": "import pandas as pd",
27+
"metadata": {
28+
"trusted": true
29+
},
30+
"execution_count": null,
31+
"outputs": [],
32+
"id": "09909708-6e45-4f96-92bc-af61031b2311"
33+
},
34+
{
35+
"cell_type": "code",
36+
"source": "pd.read_csv('data.csv')",
37+
"metadata": {
38+
"trusted": true
39+
},
40+
"execution_count": null,
41+
"outputs": [],
42+
"id": "17ad47b4-76dd-46f6-b4da-eb3ac6f96d48"
43+
}
44+
]
45+
}

docs/jupyterlite_config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab-geojson-3.2.0-pyhd8ed1ab_0.tar.bz2",
1414
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab-kernelspy-3.0.6-pyhd8ed1ab_0.tar.bz2",
1515
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_miami_nights-0.3.2-pyhd8ed1ab_0.tar.bz2",
16-
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_widgets-1.0.2-pyhd8ed1ab_0.tar.bz2",
16+
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_widgets-1.1.1-pyhd8ed1ab_0.tar.bz2",
1717
"https://conda.anaconda.org/conda-forge/noarch/plotly-5.6.0-pyhd8ed1ab_0.tar.bz2",
1818
"https://conda.anaconda.org/conda-forge/noarch/theme-darcula-3.1.1-pyh3684270_0.tar.bz2",
1919
"https://github.com/jupyterlite/p5-kernel/releases/download/v0.1.0a12/jupyterlite_p5_kernel-0.1.0a12-py3-none-any.whl"
@@ -33,7 +33,7 @@
3333
"https://files.pythonhosted.org/packages/py2.py3/i/ipython-genutils/ipython_genutils-0.2.0-py2.py3-none-any.whl",
3434
"https://files.pythonhosted.org/packages/py2.py3/i/ipyvue/ipyvue-1.7.0-py2.py3-none-any.whl",
3535
"https://files.pythonhosted.org/packages/py2.py3/i/ipyvuetify/ipyvuetify-1.8.2-1-py2.py3-none-any.whl",
36-
"https://files.pythonhosted.org/packages/py2.py3/i/ipywidgets/ipywidgets-7.6.5-py2.py3-none-any.whl",
36+
"https://files.pythonhosted.org/packages/py2.py3/i/ipywidgets/ipywidgets-7.7.1-py2.py3-none-any.whl",
3737
"https://files.pythonhosted.org/packages/py2.py3/m/mistune/mistune-0.8.4-py2.py3-none-any.whl",
3838
"https://files.pythonhosted.org/packages/py2.py3/m/mypy-extensions/mypy_extensions-0.4.3-py2.py3-none-any.whl",
3939
"https://files.pythonhosted.org/packages/py2.py3/p/pandocfilters/pandocfilters-1.5.0-py2.py3-none-any.whl",
@@ -61,7 +61,7 @@
6161
"https://files.pythonhosted.org/packages/py3/j/jsonschema/jsonschema-4.4.0-py3-none-any.whl",
6262
"https://files.pythonhosted.org/packages/py3/j/jupyter-client/jupyter_client-7.1.2-py3-none-any.whl",
6363
"https://files.pythonhosted.org/packages/py3/j/jupyter-core/jupyter_core-4.9.2-py3-none-any.whl",
64-
"https://files.pythonhosted.org/packages/py3/j/jupyterlab-widgets/jupyterlab_widgets-1.0.2-py3-none-any.whl",
64+
"https://files.pythonhosted.org/packages/py3/j/jupyterlab-widgets/jupyterlab_widgets-1.1.1-py3-none-any.whl",
6565
"https://files.pythonhosted.org/packages/py3/m/matplotlib-inline/matplotlib_inline-0.1.3-py3-none-any.whl",
6666
"https://files.pythonhosted.org/packages/py3/n/nbclient/nbclient-0.5.11-py3-none-any.whl",
6767
"https://files.pythonhosted.org/packages/py3/n/nbconvert/nbconvert-6.4.2-py3-none-any.whl",

src/jupyterlite_sphinx.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def run(self):
198198

199199
# Copy the Notebook for RetroLite to find
200200
os.makedirs(os.path.dirname(notebooks_dir), exist_ok=True)
201-
shutil.copyfile(notebook, str(notebooks_dir))
201+
try:
202+
shutil.copyfile(notebook, str(notebooks_dir))
203+
except shutil.SameFileError:
204+
pass
202205
else:
203206
notebook_name = None
204207

@@ -267,7 +270,31 @@ def jupyterlite_build(app: Sphinx, error):
267270
if app.env.config.jupyterlite_config:
268271
config = ["--config", app.env.config.jupyterlite_config]
269272

273+
contents = []
274+
if app.env.config.jupyterlite_contents:
275+
jupyterlite_contents = app.env.config.jupyterlite_contents
276+
277+
if isinstance(jupyterlite_contents, str):
278+
contents.extend(["--contents", jupyterlite_contents])
279+
280+
if isinstance(jupyterlite_contents, (tuple, list)):
281+
for content in jupyterlite_contents:
282+
contents.extend(["--contents", content])
283+
270284
command = [
285+
"jupyter",
286+
"lite",
287+
"build",
288+
"--debug",
289+
*config,
290+
*contents,
291+
"--contents",
292+
os.path.join(app.srcdir, CONTENT_DIR),
293+
"--output-dir",
294+
os.path.join(app.outdir, JUPYTERLITE_DIR),
295+
]
296+
297+
[
271298
"jupyter",
272299
"lite",
273300
"build",
@@ -310,6 +337,7 @@ def setup(app):
310337
# Config options
311338
app.add_config_value("jupyterlite_config", None, rebuild="html")
312339
app.add_config_value("jupyterlite_dir", None, rebuild="html")
340+
app.add_config_value("jupyterlite_contents", None, rebuild="html")
313341

314342
# Initialize RetroLite and JupyterLite directives
315343
app.add_node(

0 commit comments

Comments
 (0)