1
1
"""a JupyterLite addon for creating the env for xeus-python"""
2
2
import os
3
- from subprocess import (
4
- check_call ,
5
- DEVNULL
6
- )
3
+ from subprocess import check_call , DEVNULL
7
4
from tempfile import TemporaryDirectory
8
5
import shutil
9
6
from pathlib import Path
10
7
11
- from traitlets import List
8
+ from traitlets import List , Unicode
12
9
13
10
from empack .file_packager import pack_python_core
14
11
15
12
from jupyterlite .constants import SHARE_LABEXTENSIONS
16
13
from jupyterlite .addons .federated_extensions import FederatedExtensionAddon
17
14
15
+ # TODO Make this configurable
18
16
PYTHON_VERSION = "3.10"
19
17
20
18
CHANNELS = [
21
19
"https://repo.mamba.pm/emscripten-forge" ,
22
- "https://repo.mamba.pm/conda-forge"
20
+ "https://repo.mamba.pm/conda-forge" ,
23
21
]
24
22
PLATFORM = "emscripten-32"
25
23
26
24
SILENT = dict (stdout = DEVNULL , stderr = DEVNULL )
27
25
28
26
try :
29
27
from mamba .api import create as mamba_create
28
+
30
29
MAMBA_PYTHON_AVAILABLE = True
31
30
except ImportError :
32
31
MAMBA_PYTHON_AVAILABLE = False
@@ -59,15 +58,25 @@ class XeusPythonEnv(FederatedExtensionAddon):
59
58
60
59
__all__ = ["pre_build" , "post_build" ]
61
60
61
+ xeus_python_version = Unicode ().tag (
62
+ config = True , description = "The xeus-python version to use"
63
+ )
64
+
62
65
packages = PackagesList ([]).tag (
63
66
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" ,
65
68
)
66
69
67
70
@property
68
71
def specs (self ):
69
72
"""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
+ ]
71
80
72
81
@property
73
82
def prefix_path (self ):
@@ -90,7 +99,7 @@ def __init__(self, *args, **kwargs):
90
99
def pre_build (self , manager ):
91
100
"""yield a doit task to create the emscripten-32 env and grab anything we need from it"""
92
101
# Bail early if there is nothing to do
93
- if not self .packages :
102
+ if not self .packages and not self . xeus_python_version :
94
103
return []
95
104
96
105
# Create emscripten env with the given packages
@@ -149,7 +158,7 @@ def create_env(self):
149
158
base_prefix = self .root_prefix ,
150
159
specs = self .specs ,
151
160
channels = CHANNELS ,
152
- target_platform = PLATFORM
161
+ target_platform = PLATFORM ,
153
162
)
154
163
return
155
164
@@ -191,14 +200,7 @@ def create_env(self):
191
200
192
201
def _create_env_with_config (self , conda , channels ):
193
202
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 ],
202
204
cwd = self .cwd .name ,
203
205
)
204
206
self ._create_config ()
@@ -223,7 +225,7 @@ def _create_config(self):
223
225
def post_build (self , manager ):
224
226
"""Cleanup"""
225
227
# Bail early if there is nothing to do
226
- if not self .packages :
228
+ if not self .packages and not self . xeus_python_version :
227
229
return []
228
230
229
231
shutil .rmtree (self .cwd .name , ignore_errors = True )
0 commit comments