Skip to content

Commit

Permalink
Merge pull request #73 from jasongrout-db/contents
Browse files Browse the repository at this point in the history
Restore jupyterlite_contents being optionally a string
  • Loading branch information
martinRenou authored Aug 17, 2022
2 parents 3927797 + 3638e80 commit 27ca883
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ You can embed custom content (notebooks and data files) in your JupyterLite buil
jupyterlite_contents = ["./path/to/my/notebooks/", "my_other_notebook.ipynb"]
``jupyterlite_contents`` can be a string or a list of strings. Each string is expanded using the Python ``glob.glob`` function with its recursive option. See the `glob documentation <https://docs.python.org/3/library/glob.html#glob.glob>`_ and the `wildcard pattern documentation <https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch>`_ for more details.

JupyterLite dir
---------------

Expand Down
27 changes: 14 additions & 13 deletions jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,27 @@ def jupyterlite_build(app: Sphinx, error):
print("[jupyterlite-sphinx] Running JupyterLite build")
jupyterlite_config = app.env.config.jupyterlite_config
jupyterlite_contents = app.env.config.jupyterlite_contents
if jupyterlite_contents is not None:
jupyterlite_contents = [
match
for pattern in jupyterlite_contents
for match in glob.glob(pattern, recursive=True)
]
jupyterlite_dir = app.env.config.jupyterlite_dir

config = []
if jupyterlite_config:
config = ["--config", jupyterlite_config]

contents = []
if jupyterlite_contents:
if isinstance(jupyterlite_contents, str):
contents.extend(["--contents", jupyterlite_contents])
if jupyterlite_contents is None:
jupyterlite_contents = []
elif isinstance(jupyterlite_contents, str):
jupyterlite_contents = [jupyterlite_contents]

# Expand globs in the contents strings
jupyterlite_contents = [
match
for pattern in jupyterlite_contents
for match in glob.glob(pattern, recursive=True)
]

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

command = [
"jupyter",
Expand Down

0 comments on commit 27ca883

Please sign in to comment.