diff --git a/jupyterlite_xeus_python/env_build_addon.py b/jupyterlite_xeus_python/env_build_addon.py index adfb80b..a6eb9d0 100644 --- a/jupyterlite_xeus_python/env_build_addon.py +++ b/jupyterlite_xeus_python/env_build_addon.py @@ -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 @@ -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" @@ -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): @@ -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=[ ( @@ -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: @@ -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 diff --git a/tests/test_xeus_python_env.py b/tests/test_xeus_python_env.py index 3caa74f..3fe5c9b 100644 --- a/tests/test_xeus_python_env.py +++ b/tests/test_xeus_python_env.py @@ -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(): @@ -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