1
1
"""a JupyterLite addon for creating the env for xeus-python"""
2
2
import os
3
- from subprocess import check_call , DEVNULL
3
+ from subprocess import check_call , run , DEVNULL
4
4
from tempfile import TemporaryDirectory
5
5
import json
6
6
import shutil
16
16
ENV_EXTENSIONS ,
17
17
)
18
18
19
- JUPYTERLITE_XEUS_PYTHON_DEBUG = 'JUPYTERLITE_XEUS_PYTHON_DEBUG'
20
-
21
19
JUPYTERLITE_XEUS_PYTHON = "@jupyterlite/xeus-python-kernel"
22
20
23
21
# TODO Make this configurable
@@ -160,16 +158,6 @@ def post_build(self, manager):
160
158
],
161
159
)
162
160
163
- if not os .environ .get (JUPYTERLITE_XEUS_PYTHON_DEBUG , False ):
164
- # Cleanup
165
- shutil .rmtree (self .cwd .name , ignore_errors = True )
166
- shutil .rmtree (self .root_prefix , ignore_errors = True )
167
-
168
- if self .orig_config is not None :
169
- os .environ ["CONDARC" ] = self .orig_config
170
- elif "CONDARC" in os .environ :
171
- del os .environ ["CONDARC" ]
172
-
173
161
def create_env (self ):
174
162
"""Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
175
163
if MAMBA_PYTHON_AVAILABLE :
@@ -192,7 +180,7 @@ def create_env(self):
192
180
return self ._create_env_with_config ("mamba" , channels )
193
181
194
182
if MICROMAMBA_AVAILABLE :
195
- check_call (
183
+ run (
196
184
[
197
185
"micromamba" ,
198
186
"create" ,
@@ -206,6 +194,7 @@ def create_env(self):
206
194
* self .specs ,
207
195
],
208
196
cwd = self .cwd .name ,
197
+ check = True ,
209
198
)
210
199
return
211
200
@@ -219,12 +208,13 @@ def create_env(self):
219
208
)
220
209
221
210
def _create_env_with_config (self , conda , channels ):
222
- check_call (
211
+ run (
223
212
[conda , "create" , "--yes" , "--prefix" , self .prefix_path , * channels ],
224
213
cwd = self .cwd .name ,
214
+ check = True ,
225
215
)
226
216
self ._create_config ()
227
- check_call (
217
+ run (
228
218
[
229
219
conda ,
230
220
"install" ,
@@ -235,6 +225,7 @@ def _create_env_with_config(self, conda, channels):
235
225
* self .specs ,
236
226
],
237
227
cwd = self .cwd .name ,
228
+ check = True ,
238
229
)
239
230
240
231
def _create_config (self ):
@@ -260,3 +251,12 @@ def safe_copy_extension(self, pkg_json):
260
251
file_dep = file_dep ,
261
252
actions = [(self .copy_one , [pkg_path , dest ])],
262
253
)
254
+
255
+ def __del__ (self ):
256
+ # Cleanup
257
+ shutil .rmtree (self .root_prefix , ignore_errors = True )
258
+
259
+ if self .orig_config is not None :
260
+ os .environ ["CONDARC" ] = self .orig_config
261
+ elif "CONDARC" in os .environ :
262
+ del os .environ ["CONDARC" ]
0 commit comments