Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit b5b64da

Browse files
authored
Merge pull request #24 from martinRenou/xeus-python-ver
Make xeus-python version configurable
2 parents dd8e043 + 24cde68 commit b5b64da

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

jupyterlite_xeus_python/__init__.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
1010
def _jupyter_labextension_paths():
1111
prefix = sys.prefix
1212
# For when in dev mode
13-
if (HERE.parent / 'share' / 'jupyter' / 'labextensions' / '@jupyterlite' / 'xeus-python-kernel').parent.exists():
13+
if (
14+
HERE.parent
15+
/ "share"
16+
/ "jupyter"
17+
/ "labextensions"
18+
/ "@jupyterlite"
19+
/ "xeus-python-kernel"
20+
).parent.exists():
1421
prefix = HERE.parent
1522

16-
return [{
17-
'src': prefix / 'share' / 'jupyter' / 'labextensions' / '@jupyterlite' / 'xeus-python-kernel',
18-
'dest': '@jupyterlite/xeus-python-kernel',
19-
}]
23+
return [
24+
{
25+
"src": prefix
26+
/ "share"
27+
/ "jupyter"
28+
/ "labextensions"
29+
/ "@jupyterlite"
30+
/ "xeus-python-kernel",
31+
"dest": "@jupyterlite/xeus-python-kernel",
32+
}
33+
]

jupyterlite_xeus_python/env_build_addon.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
"""a JupyterLite addon for creating the env for xeus-python"""
22
import os
3-
from subprocess import (
4-
check_call,
5-
DEVNULL
6-
)
3+
from subprocess import check_call, DEVNULL
74
from tempfile import TemporaryDirectory
85
import shutil
96
from pathlib import Path
107

11-
from traitlets import List
8+
from traitlets import List, Unicode
129

1310
from empack.file_packager import pack_python_core
1411

1512
from jupyterlite.constants import SHARE_LABEXTENSIONS
1613
from jupyterlite.addons.federated_extensions import FederatedExtensionAddon
1714

15+
# TODO Make this configurable
1816
PYTHON_VERSION = "3.10"
1917

2018
CHANNELS = [
2119
"https://repo.mamba.pm/emscripten-forge",
22-
"https://repo.mamba.pm/conda-forge"
20+
"https://repo.mamba.pm/conda-forge",
2321
]
2422
PLATFORM = "emscripten-32"
2523

2624
SILENT = dict(stdout=DEVNULL, stderr=DEVNULL)
2725

2826
try:
2927
from mamba.api import create as mamba_create
28+
3029
MAMBA_PYTHON_AVAILABLE = True
3130
except ImportError:
3231
MAMBA_PYTHON_AVAILABLE = False
@@ -59,15 +58,25 @@ class XeusPythonEnv(FederatedExtensionAddon):
5958

6059
__all__ = ["pre_build", "post_build"]
6160

61+
xeus_python_version = Unicode().tag(
62+
config=True, description="The xeus-python version to use"
63+
)
64+
6265
packages = PackagesList([]).tag(
6366
config=True,
64-
description="A comma-separated list of packages to install in the xeus-python env"
67+
description="A comma-separated list of packages to install in the xeus-python env",
6568
)
6669

6770
@property
6871
def specs(self):
6972
"""The package specs to install in the environment."""
70-
return [f"python={PYTHON_VERSION}", "xeus-python", *self.packages]
73+
return [
74+
f"python={PYTHON_VERSION}",
75+
"xeus-python"
76+
if not self.xeus_python_version
77+
else f"xeus-python={self.xeus_python_version}",
78+
*self.packages,
79+
]
7180

7281
@property
7382
def prefix_path(self):
@@ -90,7 +99,7 @@ def __init__(self, *args, **kwargs):
9099
def pre_build(self, manager):
91100
"""yield a doit task to create the emscripten-32 env and grab anything we need from it"""
92101
# Bail early if there is nothing to do
93-
if not self.packages:
102+
if not self.packages and not self.xeus_python_version:
94103
return []
95104

96105
# Create emscripten env with the given packages
@@ -149,7 +158,7 @@ def create_env(self):
149158
base_prefix=self.root_prefix,
150159
specs=self.specs,
151160
channels=CHANNELS,
152-
target_platform=PLATFORM
161+
target_platform=PLATFORM,
153162
)
154163
return
155164

@@ -191,14 +200,7 @@ def create_env(self):
191200

192201
def _create_env_with_config(self, conda, channels):
193202
check_call(
194-
[
195-
conda,
196-
"create",
197-
"--yes",
198-
"--prefix",
199-
self.prefix_path,
200-
*channels
201-
],
203+
[conda, "create", "--yes", "--prefix", self.prefix_path, *channels],
202204
cwd=self.cwd.name,
203205
)
204206
self._create_config()
@@ -223,7 +225,7 @@ def _create_config(self):
223225
def post_build(self, manager):
224226
"""Cleanup"""
225227
# Bail early if there is nothing to do
226-
if not self.packages:
228+
if not self.packages and not self.xeus_python_version:
227229
return []
228230

229231
shutil.rmtree(self.cwd.name, ignore_errors=True)

0 commit comments

Comments
 (0)