Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.
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
32 changes: 16 additions & 16 deletions jupyterlite_xeus_python/env_build_addon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""a JupyterLite addon for creating the env for xeus-python"""
import os
from subprocess import check_call, DEVNULL
from subprocess import check_call, run, DEVNULL
from tempfile import TemporaryDirectory
import json
import shutil
Expand All @@ -16,8 +16,6 @@
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 @@ -160,16 +158,6 @@ def post_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 All @@ -192,7 +180,7 @@ def create_env(self):
return self._create_env_with_config("mamba", channels)

if MICROMAMBA_AVAILABLE:
check_call(
run(
[
"micromamba",
"create",
Expand All @@ -206,6 +194,7 @@ def create_env(self):
*self.specs,
],
cwd=self.cwd.name,
check=True,
)
return

Expand All @@ -219,12 +208,13 @@ def create_env(self):
)

def _create_env_with_config(self, conda, channels):
check_call(
run(
[conda, "create", "--yes", "--prefix", self.prefix_path, *channels],
cwd=self.cwd.name,
check=True,
)
self._create_config()
check_call(
run(
[
conda,
"install",
Expand All @@ -235,6 +225,7 @@ def _create_env_with_config(self, conda, channels):
*self.specs,
],
cwd=self.cwd.name,
check=True,
)

def _create_config(self):
Expand All @@ -260,3 +251,12 @@ def safe_copy_extension(self, pkg_json):
file_dep=file_dep,
actions=[(self.copy_one, [pkg_path, dest])],
)

def __del__(self):
# Cleanup
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"]
4 changes: 1 addition & 3 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, JUPYTERLITE_XEUS_PYTHON_DEBUG
from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv


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

os.environ[JUPYTERLITE_XEUS_PYTHON_DEBUG] = "True"

for step in addon.post_build(manager):
pass

Expand Down