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

Commit 782da38

Browse files
authored
Merge pull request #34 from martinRenou/fix_cleanup
Fix temporary directories cleanup so that it happens after the tasks
2 parents b4c6e7a + 0641cb0 commit 782da38

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

jupyterlite_xeus_python/env_build_addon.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""a JupyterLite addon for creating the env for xeus-python"""
22
import os
3-
from subprocess import check_call, DEVNULL
3+
from subprocess import check_call, run, DEVNULL
44
from tempfile import TemporaryDirectory
55
import json
66
import shutil
@@ -16,8 +16,6 @@
1616
ENV_EXTENSIONS,
1717
)
1818

19-
JUPYTERLITE_XEUS_PYTHON_DEBUG = 'JUPYTERLITE_XEUS_PYTHON_DEBUG'
20-
2119
JUPYTERLITE_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"]

tests/test_xeus_python_env.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from jupyterlite.app import LiteStatusApp
88

9-
from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv, JUPYTERLITE_XEUS_PYTHON_DEBUG
9+
from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv
1010

1111

1212
def test_python_env():
@@ -17,8 +17,6 @@ def test_python_env():
1717
addon = XeusPythonEnv(manager)
1818
addon.packages = ["numpy", "ipyleaflet"]
1919

20-
os.environ[JUPYTERLITE_XEUS_PYTHON_DEBUG] = "True"
21-
2220
for step in addon.post_build(manager):
2321
pass
2422

0 commit comments

Comments
 (0)