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 9 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
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"myst_parser",
]

myst_enable_extensions = [
"colon_fence"
]

html_theme = "pydata_sphinx_theme"
html_logo = "_static/icon.svg"

Expand Down
26 changes: 26 additions & 0 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 @@ -75,3 +75,29 @@ jupyterlite_silence = False
```

in your Sphinx `conf.py`.

steppi marked this conversation as resolved.
Show resolved Hide resolved
## Additional CLI arguments for `jupyter lite build`

You can pass additional arguments to the `jupyter lite build` command by passing a dictionary of arguments to the `jupyterlite_build_command_options` configuration option, without the hyphens prepended to the keys. Here's an example:

```python
jupyterlite_build_command_options = {
"port": 8888,
"XeusAddon.environment_file": "jupyterlite_environment.yml",
"source-date-epoch": "315532800",
}
```
steppi marked this conversation as resolved.
Show resolved Hide resolved

This will launch the JupyterLite site on port 8888, configure the `jupyterlite-xeus` kernel with a custom
`jupyterlite_environment.yml` file, and configure the source date epoch to ensure reproducible builds.

:::{attention}
The `--contents`, `--output-dir`, and `--lite-dir` options are not supported in this scenario, as they are set by
the [`jupyterlite_contents`](#jupyterlite-content) and the[`jupyterlite_dir`](#jupyterlite-dir) configuration
options, respectively, as described above.
:::

:::{seealso}
The full list of available options can be found by running the `jupyter lite build --help-all` command. For more
information, please visit the [JupyterLite documentation](https://jupyterlite.readthedocs.io/en/stable/reference/cli.html#usage).
:::
steppi marked this conversation as resolved.
Show resolved Hide resolved
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