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

Commit 8b411ba

Browse files
committed
Make sure xeus-python kernel emscripten build runs after the
FederatedExtension addon
1 parent 2302b6d commit 8b411ba

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

jupyterlite_xeus_python/env_build_addon.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
ENV_EXTENSIONS,
1717
)
1818

19+
JUPYTERLITE_XEUS_PYTHON_DEBUG = 'JUPYTERLITE_XEUS_PYTHON_DEBUG'
20+
1921
JUPYTERLITE_XEUS_PYTHON = "@jupyterlite/xeus-python-kernel"
2022

2123
# TODO Make this configurable
@@ -62,7 +64,7 @@ def from_string(self, s):
6264

6365
class XeusPythonEnv(FederatedExtensionAddon):
6466

65-
__all__ = ["pre_build", "post_build"]
67+
__all__ = ["post_build"]
6668

6769
xeus_python_version = Unicode().tag(
6870
config=True, description="The xeus-python version to use"
@@ -102,7 +104,7 @@ def __init__(self, *args, **kwargs):
102104

103105
self.orig_config = os.environ.get("CONDARC")
104106

105-
def pre_build(self, manager):
107+
def post_build(self, manager):
106108
"""yield a doit task to create the emscripten-32 env and grab anything we need from it"""
107109
# Install the jupyterlite-xeus-python ourselves
108110
for pkg_json in self.env_extensions(ENV_EXTENSIONS):
@@ -138,18 +140,14 @@ def pre_build(self, manager):
138140
# (make jupyterlite-xeus-python extension somewhat configurable?)
139141
dest = self.output_extensions / "@jupyterlite" / "xeus-python-kernel" / "static"
140142

141-
task_dep = ["pre_build:federated_extensions:*"]
142-
143143
for file in ["python_data.js", "python_data.data"]:
144144
yield dict(
145-
task_dep=task_dep,
146145
name=f"xeus:copy:{file}",
147146
actions=[(self.copy_one, [Path(self.cwd.name) / file, dest / file])],
148147
)
149148

150149
for file in ["xpython_wasm.js", "xpython_wasm.wasm"]:
151150
yield dict(
152-
task_dep=task_dep,
153151
name=f"xeus:copy:{file}",
154152
actions=[
155153
(
@@ -162,6 +160,16 @@ def pre_build(self, manager):
162160
],
163161
)
164162

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+
165173
def create_env(self):
166174
"""Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
167175
if MAMBA_PYTHON_AVAILABLE:
@@ -234,22 +242,6 @@ def _create_config(self):
234242
fobj.write(f"subdir: {PLATFORM}")
235243
os.environ["CONDARC"] = str(self.prefix_path / ".condarc")
236244

237-
def post_build(self, manager):
238-
"""Cleanup"""
239-
# Bail early if there is nothing to do
240-
if not self.packages and not self.xeus_python_version:
241-
return []
242-
243-
shutil.rmtree(self.cwd.name, ignore_errors=True)
244-
shutil.rmtree(self.root_prefix, ignore_errors=True)
245-
246-
if self.orig_config is not None:
247-
os.environ["CONDARC"] = self.orig_config
248-
elif "CONDARC" in os.environ:
249-
del os.environ["CONDARC"]
250-
251-
return []
252-
253245
def safe_copy_extension(self, pkg_json):
254246
"""Copy a labextension, and overwrite it
255247
if it's already in the output

tests/test_xeus_python_env.py

+4-2
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
9+
from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv, JUPYTERLITE_XEUS_PYTHON_DEBUG
1010

1111

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

20-
for step in addon.pre_build(manager):
20+
os.environ[JUPYTERLITE_XEUS_PYTHON_DEBUG] = True
21+
22+
for step in addon.post_build(manager):
2123
pass
2224

2325
# Check env

0 commit comments

Comments
 (0)