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

Use shutil.which() in subprocess.check_call() when executing mamba/micromamba/conda #103

Merged
merged 2 commits into from Jan 2, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -124,3 +124,6 @@ src/web_worker_kernel.ts

# Labextension
share

# venv
.venv
31 changes: 9 additions & 22 deletions jupyterlite_xeus_python/env_build_addon.py
Expand Up @@ -47,24 +47,11 @@
except ImportError:
MAMBA_PYTHON_AVAILABLE = False

try:
check_call(["mamba", "--version"], **SILENT)
MAMBA_AVAILABLE = True
except FileNotFoundError:
MAMBA_AVAILABLE = False

try:
check_call(["micromamba", "--version"], **SILENT)
MICROMAMBA_AVAILABLE = True
except FileNotFoundError:
MICROMAMBA_AVAILABLE = False
MAMBA_COMMAND = shutil.which("mamba")

try:
check_call(["conda", "--version"], **SILENT)
CONDA_AVAILABLE = True
except FileNotFoundError:
CONDA_AVAILABLE = False
MICROMAMBA_COMMAND = shutil.which("micromamba")

CONDA_COMMAND = shutil.which("conda")

class PackagesList(List):
def from_string(self, s):
Expand Down Expand Up @@ -252,15 +239,15 @@ def create_env(self):
for channel in self.channels:
channels.extend(["-c", channel])

if MAMBA_AVAILABLE:
if MAMBA_COMMAND:
# Mamba needs the directory to exist already
self.prefix_path.mkdir(parents=True, exist_ok=True)
return self._create_env_with_config("mamba", channels)
return self._create_env_with_config(MAMBA_COMMAND, channels)

if MICROMAMBA_AVAILABLE:
if MICROMAMBA_COMMAND:
run(
[
"micromamba",
MICROMAMBA_COMMAND,
"create",
"--yes",
"--root-prefix",
Expand All @@ -276,8 +263,8 @@ def create_env(self):
)
return

if CONDA_AVAILABLE:
return self._create_env_with_config("conda", channels)
if CONDA_COMMAND:
return self._create_env_with_config(CONDA_COMMAND, channels)

raise RuntimeError(
"""Failed to create the virtual environment for xeus-python,
Expand Down