Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass additional configuration options to the jupyter lite build command #169

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
617a614
Un-silence JupyterLite output by default
agriyakhetarpal Apr 29, 2024
6eb6680
Add `jupyterlite_build_command_options` dictionary
agriyakhetarpal Apr 29, 2024
78b4a37
Revert "Un-silence JupyterLite output by default"
agriyakhetarpal Apr 29, 2024
9f13354
Don't convert between cases, keep hyphens
agriyakhetarpal Apr 29, 2024
e7a3446
Some general fixes (punctuation, backticks, etc.)
agriyakhetarpal Apr 29, 2024
511b5c6
Revert "Some general fixes (punctuation, backticks, etc.)"
agriyakhetarpal Apr 29, 2024
0b5e499
Enable `colon_fence` for admonitions
agriyakhetarpal Apr 29, 2024
f6e6d3b
Add documentation about additional arguments
agriyakhetarpal Apr 29, 2024
28c42f0
Fix incorrect reference to dict
agriyakhetarpal Apr 29, 2024
d1acb88
Remove unneeded build command options
agriyakhetarpal Apr 29, 2024
6cc2cab
Remove admonitions and `colon_fence` extension
agriyakhetarpal Apr 29, 2024
7b954c4
Clarify sentences for usage of additional options
agriyakhetarpal Apr 29, 2024
d49069e
Add additional note about complexity of usage
agriyakhetarpal Apr 29, 2024
93d39b0
Convert dict values to `str` before passing to subprocess
agriyakhetarpal Apr 29, 2024
cf465d1
Improve error message by emulating invalid options
agriyakhetarpal Apr 30, 2024
948a8c8
Raise `RuntimeError` if configuration option received
agriyakhetarpal Apr 30, 2024
e1a8e6e
Merge branch 'main' into jupyterlite-cli-additional-options
agriyakhetarpal Apr 30, 2024
5719e33
Fix case in list of invalid options
agriyakhetarpal Apr 30, 2024
a9ca886
Update docs about precedence of CLI options
agriyakhetarpal Apr 30, 2024
d1460c1
Do not directly mention precedence for CLI options
agriyakhetarpal Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/configuration.md
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ You would need `jupyterlite-xeus` installed in your docs build environment.

You can pre-install packages by adding an `environment.yml` file in the docs directory, with `xeus-python` defined as one of the dependencies. It will pre-build the environment when running the `jupyter lite build`.

Furthermore, this automatically installs any labextension that it founds, for example installing ipyleaflet will make ipyleaflet work without the need to manually install the jupyter-leaflet labextension.
Furthermore, this automatically installs any labextension that it finds, for example, installing `ipyleaflet` will make `ipyleaflet` work without the need to manually install the `jupyter-leaflet` labextension.

Say you want to install NumPy, Matplotlib and ipycanvas, it can be done by creating the environment.yml file with the following content:
Say you want to install NumPy, Matplotlib and ipycanvas, it can be done by creating the `environment.yml` file with the following content:

```yaml
name: xeus-python-kernel
Expand All @@ -56,19 +56,19 @@ jupyterlite_config = "jupyterlite_config.json"
## Disable the `.ipynb` docs source binding

By default, jupyterlite-sphinx binds the `.ipynb` source suffix so that it renders Notebooks included in the doctree with JupyterLite.
This is known to bring warnings with plugins like sphinx-gallery, or to conflict with nbsphinx.
This is known to bring warnings with plugins like `sphinx-gallery`, or to conflict with `nbsphinx`.

You can disable this behavior by setting the following config:

```python
jupyterlite_bind_ipynb_suffix = False
```

### Suppressing jupyterlite logging
### Suppressing JupyterLite logging

`jupyterlite` can produce large amounts of output to the terminal when docs are building.
By default, this output is silenced, but will still be printed if the invocation of
`jupyterlite build` fails. To unsilence this output, set
`jupyter lite build` fails. To unsilence this output, set

```python
jupyterlite_silence = False
Expand Down
23 changes: 23 additions & 0 deletions jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ def jupyterlite_build(app: Sphinx, error):

jupyterlite_dir = str(app.env.config.jupyterlite_dir)

jupyterlite_build_command_options: Dict[str, Any] = (
app.env.config.jupyterlite_build_command_options
)
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

config = []
if jupyterlite_config:
config = ["--config", jupyterlite_config]
Expand Down Expand Up @@ -614,6 +618,22 @@ def jupyterlite_build(app: Sphinx, error):
jupyterlite_dir,
]

if jupyterlite_build_command_options is not None:
for key, value in jupyterlite_build_command_options.items():
# Check for conflicting options from the default command we use
# while building. We don't want to allow these to be overridden
# unless they are explicitly set through Sphinx config.
if key in ["contents", "output_dir", "lite_dir"]:
jupyterlite_command_error_message = """
Cannot use [contents, output_dir, lite_dir] in jupyterlite_build_command_options.
Please use the corresponding option directly in conf.py.
For a list of available options, run the 'jupyter lite build --help-all'
command and refer to the documentation for jupyterlite-sphinx:
https://jupyterlite-sphinx.readthedocs.io/en/stable/configuration.html
"""
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(jupyterlite_command_error_message)
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
command.extend([f"--{key}", value])
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

assert all(
[isinstance(s, str) for s in command]
), f"Expected all commands arguments to be a str, got {command}"
Expand Down Expand Up @@ -669,6 +689,9 @@ def setup(app):
app.add_config_value("jupyterlite_bind_ipynb_suffix", True, rebuild="html")
app.add_config_value("jupyterlite_silence", True, rebuild=True)

# Pass a dictionary of additional options to the JupyterLite build command
app.add_config_value("jupyterlite_build_command_options", None, rebuild="html")

app.add_config_value("global_enable_try_examples", default=False, rebuild=True)
app.add_config_value("try_examples_global_theme", default=None, rebuild=True)
app.add_config_value("try_examples_global_warning_text", default=None, rebuild=True)
Expand Down
Loading