Skip to content

Commit

Permalink
Support environment.yaml (previously documented but not supported) or…
Browse files Browse the repository at this point in the history
… environment.yml automatically (#92)
  • Loading branch information
martinRenou authored Jun 17, 2024
1 parent 6fa187f commit 61948b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ pip install jupyterlite_xeus

## Usage

### From environment.yaml
### From environment.yml

#### xeus-python kernel

To load a `xeus-python` kernel with a custom environment, create an `environment.yaml` file with `xeus-python` and the desired dependencies. Here is an example with `numpy` as a additional dependency:
To load a `xeus-python` kernel with a custom environment, create an `environment.yml` file with `xeus-python` and the desired dependencies. Here is an example with `numpy` as a additional dependency:

```yaml
name: xeus-lite-wasm
Expand All @@ -34,10 +34,10 @@ dependencies:
- numpy
```
To build JupyterLite, run the following command where `environment.yaml` is the path to the file you just created
To build JupyterLite, run the following command where `environment.yml` is the path to the file you just created

```bash
jupyter lite build --XeusAddon.environment_file=some_path/to/environment.yaml
jupyter lite build --XeusAddon.environment_file=some_path/to/environment.yml
```

#### xeus-lua / xeus-sqlite / xeus-\<mylang\>
Expand All @@ -61,12 +61,12 @@ Note that `xeus-sqlite` and `xeus-lua` do not support additional dependencies ye
To build JupyterLite, run again:

```bash
jupyter lite build --XeusAddon.environment_file=environment.yaml
jupyter lite build --XeusAddon.environment_file=environment.yml
```

#### Multiple kernels

To create a deployment with multiple kernels, you can simply add them to the `environment.yaml` file:
To create a deployment with multiple kernels, you can simply add them to the `environment.yml` file:

```yaml
name: xeus-lite-wasm
Expand Down Expand Up @@ -155,7 +155,7 @@ Each mount is specified as a pair of paths separated by a colon `:`. The first p

```bash
jupyter lite build \
--XeusAddon.environment_file=environment.yaml \
--XeusAddon.environment_file=environment.yml \
--XeusAddon.mounts=/some/path/on/host_machine:/some/path/in/virtual/filesystem
```

Expand Down
12 changes: 10 additions & 2 deletions jupyterlite_xeus/add_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ class XeusAddon(FederatedExtensionAddon):
)

environment_file = Unicode(
"environment.yml",
None,
allow_none=True,
config=True,
description='The path to the environment file. Defaults to "environment.yml"',
description='The path to the environment file. Defaults to looking for "environment.yml" or "environment.yaml"',
)

prefix = Unicode(
Expand Down Expand Up @@ -107,6 +108,13 @@ def __init__(self, *args, **kwargs):
self.cwd = TemporaryDirectory()

def post_build(self, manager):
if self.environment_file is None:
if (Path(self.manager.lite_dir) / "environment.yml").exists():
self.environment_file = "environment.yml"

if (Path(self.manager.lite_dir) / "environment.yaml").exists():
self.environment_file = "environment.yaml"

# check that either prefix or environment_file is set
if not self.prefix and not self.environment_file:
raise ValueError("Either prefix or environment_file must be set")
Expand Down

0 comments on commit 61948b7

Please sign in to comment.