11"""a JupyterLite addon for creating the env for xeus-python"""
22import os
3- from subprocess import check_call , DEVNULL
3+ from subprocess import check_call , run , DEVNULL
44from tempfile import TemporaryDirectory
55import json
66import shutil
1616 ENV_EXTENSIONS ,
1717)
1818
19- JUPYTERLITE_XEUS_PYTHON_DEBUG = 'JUPYTERLITE_XEUS_PYTHON_DEBUG'
20-
2119JUPYTERLITE_XEUS_PYTHON = "@jupyterlite/xeus-python-kernel"
2220
2321# TODO Make this configurable
@@ -160,16 +158,6 @@ def post_build(self, manager):
160158 ],
161159 )
162160
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-
173161 def create_env (self ):
174162 """Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
175163 if MAMBA_PYTHON_AVAILABLE :
@@ -192,7 +180,7 @@ def create_env(self):
192180 return self ._create_env_with_config ("mamba" , channels )
193181
194182 if MICROMAMBA_AVAILABLE :
195- check_call (
183+ run (
196184 [
197185 "micromamba" ,
198186 "create" ,
@@ -206,6 +194,7 @@ def create_env(self):
206194 * self .specs ,
207195 ],
208196 cwd = self .cwd .name ,
197+ check = True ,
209198 )
210199 return
211200
@@ -219,12 +208,13 @@ def create_env(self):
219208 )
220209
221210 def _create_env_with_config (self , conda , channels ):
222- check_call (
211+ run (
223212 [conda , "create" , "--yes" , "--prefix" , self .prefix_path , * channels ],
224213 cwd = self .cwd .name ,
214+ check = True ,
225215 )
226216 self ._create_config ()
227- check_call (
217+ run (
228218 [
229219 conda ,
230220 "install" ,
@@ -235,6 +225,7 @@ def _create_env_with_config(self, conda, channels):
235225 * self .specs ,
236226 ],
237227 cwd = self .cwd .name ,
228+ check = True ,
238229 )
239230
240231 def _create_config (self ):
@@ -260,3 +251,12 @@ def safe_copy_extension(self, pkg_json):
260251 file_dep = file_dep ,
261252 actions = [(self .copy_one , [pkg_path , dest ])],
262253 )
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