From 61948b7c102b96cd0dd4ce9fcac2166cee9baa22 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Mon, 17 Jun 2024 14:29:21 +0100 Subject: [PATCH] Support environment.yaml (previously documented but not supported) or environment.yml automatically (#92) --- README.md | 14 +++++++------- jupyterlite_xeus/add_on.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 91188e8..0c52180 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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-\ @@ -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 @@ -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 ``` diff --git a/jupyterlite_xeus/add_on.py b/jupyterlite_xeus/add_on.py index 95a07ff..39f77da 100644 --- a/jupyterlite_xeus/add_on.py +++ b/jupyterlite_xeus/add_on.py @@ -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( @@ -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")