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

Make sure xeus-python kernel emscripten build runs after the FederatedExtension addon #32

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions jupyterlite_xeus_python/env_build_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ENV_EXTENSIONS,
)

JUPYTERLITE_XEUS_PYTHON_DEBUG = 'JUPYTERLITE_XEUS_PYTHON_DEBUG'

JUPYTERLITE_XEUS_PYTHON = "@jupyterlite/xeus-python-kernel"

# TODO Make this configurable
Expand Down Expand Up @@ -62,7 +64,7 @@ def from_string(self, s):

class XeusPythonEnv(FederatedExtensionAddon):

__all__ = ["pre_build", "post_build"]
__all__ = ["post_build"]

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

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

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

task_dep = ["pre_build:federated_extensions:*"]

for file in ["python_data.js", "python_data.data"]:
yield dict(
task_dep=task_dep,
name=f"xeus:copy:{file}",
actions=[(self.copy_one, [Path(self.cwd.name) / file, dest / file])],
)

for file in ["xpython_wasm.js", "xpython_wasm.wasm"]:
yield dict(
task_dep=task_dep,
name=f"xeus:copy:{file}",
actions=[
(
Expand All @@ -162,6 +160,16 @@ def pre_build(self, manager):
],
)

if not os.environ.get(JUPYTERLITE_XEUS_PYTHON_DEBUG, False):
# Cleanup
shutil.rmtree(self.cwd.name, ignore_errors=True)
shutil.rmtree(self.root_prefix, ignore_errors=True)

if self.orig_config is not None:
os.environ["CONDARC"] = self.orig_config
elif "CONDARC" in os.environ:
del os.environ["CONDARC"]

def create_env(self):
"""Create the xeus-python emscripten-32 env with either mamba, micromamba or conda."""
if MAMBA_PYTHON_AVAILABLE:
Expand Down Expand Up @@ -234,22 +242,6 @@ def _create_config(self):
fobj.write(f"subdir: {PLATFORM}")
os.environ["CONDARC"] = str(self.prefix_path / ".condarc")

def post_build(self, manager):
"""Cleanup"""
# Bail early if there is nothing to do
if not self.packages and not self.xeus_python_version:
return []

shutil.rmtree(self.cwd.name, ignore_errors=True)
shutil.rmtree(self.root_prefix, ignore_errors=True)

if self.orig_config is not None:
os.environ["CONDARC"] = self.orig_config
elif "CONDARC" in os.environ:
del os.environ["CONDARC"]

return []

def safe_copy_extension(self, pkg_json):
"""Copy a labextension, and overwrite it
if it's already in the output
Expand Down
6 changes: 4 additions & 2 deletions tests/test_xeus_python_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from jupyterlite.app import LiteStatusApp

from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv
from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv, JUPYTERLITE_XEUS_PYTHON_DEBUG


def test_python_env():
Expand All @@ -17,7 +17,9 @@ def test_python_env():
addon = XeusPythonEnv(manager)
addon.packages = ["numpy", "ipyleaflet"]

for step in addon.pre_build(manager):
os.environ[JUPYTERLITE_XEUS_PYTHON_DEBUG] = "True"

for step in addon.post_build(manager):
pass

# Check env
Expand Down