Skip to content

Commit

Permalink
Add jupyterlite_contents config (#24)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Fix variable shadowing

* Update src/jupyterlite_sphinx.py

Co-authored-by: Jason Grout <[email protected]>

* Update links to wheels

Co-authored-by: Jason Grout <[email protected]>
  • Loading branch information
martinRenou and jasongrout authored Jun 23, 2022
1 parent 0223c17 commit 944ccf4
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
html_logo = "_static/icon.svg"

jupyterlite_config = "jupyterlite_config.json"
jupyterlite_contents = "./custom_contents"

master_doc = 'index'

Expand Down
26 changes: 26 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
Configuration
=============

JupyterLite-sphinx can be configured in your ``conf.py`` file by setting some global Python variables:

JupyterLite content
-------------------

You can embed custom content (notebooks and data files) in your JupyterLite build by providing the following config:

.. code-block:: python
jupyterlite_contents = ["./path/to/my/notebooks/", "my_other_notebook.ipynb"]
JupyterLite dir
---------------

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:

.. code-block:: python
# Build in the current directory
jupyterlite_dir = "."
This allows for jupyterlite to automatically pick-up some paths https://jupyterlite.readthedocs.io/en/latest/reference/cli.html#the-lite-dir

JupyterLite config
------------------

You can provide `custom configuration <https://jupyterlite.readthedocs.io/en/latest/configuring.html>`_ to your JupyterLite deployment.

For example, if you want to have bqplot working in this deployment, you need to install the bqplot federated extension
Expand Down
4 changes: 4 additions & 0 deletions docs/custom_contents/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A,B,C,D
1,2,3,4
7,8,9,10
32,45,90,54
45 changes: 45 additions & 0 deletions docs/custom_contents/read_csv.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"metadata": {
"kernelspec": {
"name": "python",
"display_name": "Pyolite",
"language": "python"
},
"language_info": {
"codemirror_mode": {
"name": "python",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8"
}
},
"nbformat_minor": 5,
"nbformat": 4,
"cells": [
{
"cell_type": "code",
"source": "import pandas as pd",
"metadata": {
"trusted": true
},
"execution_count": null,
"outputs": [],
"id": "09909708-6e45-4f96-92bc-af61031b2311"
},
{
"cell_type": "code",
"source": "pd.read_csv('data.csv')",
"metadata": {
"trusted": true
},
"execution_count": null,
"outputs": [],
"id": "17ad47b4-76dd-46f6-b4da-eb3ac6f96d48"
}
]
}
6 changes: 3 additions & 3 deletions docs/jupyterlite_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab-geojson-3.2.0-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab-kernelspy-3.0.6-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_miami_nights-0.3.2-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_widgets-1.0.2-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/jupyterlab_widgets-1.1.1-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/plotly-5.6.0-pyhd8ed1ab_0.tar.bz2",
"https://conda.anaconda.org/conda-forge/noarch/theme-darcula-3.1.1-pyh3684270_0.tar.bz2",
"https://github.com/jupyterlite/p5-kernel/releases/download/v0.1.0a12/jupyterlite_p5_kernel-0.1.0a12-py3-none-any.whl"
Expand All @@ -33,7 +33,7 @@
"https://files.pythonhosted.org/packages/py2.py3/i/ipython-genutils/ipython_genutils-0.2.0-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/i/ipyvue/ipyvue-1.7.0-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/i/ipyvuetify/ipyvuetify-1.8.2-1-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/i/ipywidgets/ipywidgets-7.6.5-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/i/ipywidgets/ipywidgets-7.7.1-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/m/mistune/mistune-0.8.4-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/m/mypy-extensions/mypy_extensions-0.4.3-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/p/pandocfilters/pandocfilters-1.5.0-py2.py3-none-any.whl",
Expand Down Expand Up @@ -61,7 +61,7 @@
"https://files.pythonhosted.org/packages/py3/j/jsonschema/jsonschema-4.4.0-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/j/jupyter-client/jupyter_client-7.1.2-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/j/jupyter-core/jupyter_core-4.9.2-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/j/jupyterlab-widgets/jupyterlab_widgets-1.0.2-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/j/jupyterlab-widgets/jupyterlab_widgets-1.1.1-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/m/matplotlib-inline/matplotlib_inline-0.1.3-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/n/nbclient/nbclient-0.5.11-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py3/n/nbconvert/nbconvert-6.4.2-py3-none-any.whl",
Expand Down
30 changes: 29 additions & 1 deletion src/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def run(self):

# Copy the Notebook for RetroLite to find
os.makedirs(os.path.dirname(notebooks_dir), exist_ok=True)
shutil.copyfile(notebook, str(notebooks_dir))
try:
shutil.copyfile(notebook, str(notebooks_dir))
except shutil.SameFileError:
pass
else:
notebook_name = None

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

contents = []
if app.env.config.jupyterlite_contents:
jupyterlite_contents = app.env.config.jupyterlite_contents

if isinstance(jupyterlite_contents, str):
contents.extend(["--contents", jupyterlite_contents])

if isinstance(jupyterlite_contents, (tuple, list)):
for content in jupyterlite_contents:
contents.extend(["--contents", content])

command = [
"jupyter",
"lite",
"build",
"--debug",
*config,
*contents,
"--contents",
os.path.join(app.srcdir, CONTENT_DIR),
"--output-dir",
os.path.join(app.outdir, JUPYTERLITE_DIR),
]

[
"jupyter",
"lite",
"build",
Expand Down Expand Up @@ -310,6 +337,7 @@ def setup(app):
# Config options
app.add_config_value("jupyterlite_config", None, rebuild="html")
app.add_config_value("jupyterlite_dir", None, rebuild="html")
app.add_config_value("jupyterlite_contents", None, rebuild="html")

# Initialize RetroLite and JupyterLite directives
app.add_node(
Expand Down

0 comments on commit 944ccf4

Please sign in to comment.