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

Commit b61f799

Browse files
authoredJan 2, 2023
Use shutil.which() in subprocess.check_call() when executing mamba/micromamba/conda (#103)
* Use shutil.which() in subprocess.check_call() * simplify package manager detection
1 parent c795de4 commit b61f799

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,6 @@ src/web_worker_kernel.ts
124124

125125
# Labextension
126126
share
127+
128+
# venv
129+
.venv

‎jupyterlite_xeus_python/env_build_addon.py

+9-22
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,11 @@
4747
except ImportError:
4848
MAMBA_PYTHON_AVAILABLE = False
4949

50-
try:
51-
check_call(["mamba", "--version"], **SILENT)
52-
MAMBA_AVAILABLE = True
53-
except FileNotFoundError:
54-
MAMBA_AVAILABLE = False
55-
56-
try:
57-
check_call(["micromamba", "--version"], **SILENT)
58-
MICROMAMBA_AVAILABLE = True
59-
except FileNotFoundError:
60-
MICROMAMBA_AVAILABLE = False
50+
MAMBA_COMMAND = shutil.which("mamba")
6151

62-
try:
63-
check_call(["conda", "--version"], **SILENT)
64-
CONDA_AVAILABLE = True
65-
except FileNotFoundError:
66-
CONDA_AVAILABLE = False
52+
MICROMAMBA_COMMAND = shutil.which("micromamba")
6753

54+
CONDA_COMMAND = shutil.which("conda")
6855

6956
class PackagesList(List):
7057
def from_string(self, s):
@@ -252,15 +239,15 @@ def create_env(self):
252239
for channel in self.channels:
253240
channels.extend(["-c", channel])
254241

255-
if MAMBA_AVAILABLE:
242+
if MAMBA_COMMAND:
256243
# Mamba needs the directory to exist already
257244
self.prefix_path.mkdir(parents=True, exist_ok=True)
258-
return self._create_env_with_config("mamba", channels)
245+
return self._create_env_with_config(MAMBA_COMMAND, channels)
259246

260-
if MICROMAMBA_AVAILABLE:
247+
if MICROMAMBA_COMMAND:
261248
run(
262249
[
263-
"micromamba",
250+
MICROMAMBA_COMMAND,
264251
"create",
265252
"--yes",
266253
"--root-prefix",
@@ -276,8 +263,8 @@ def create_env(self):
276263
)
277264
return
278265

279-
if CONDA_AVAILABLE:
280-
return self._create_env_with_config("conda", channels)
266+
if CONDA_COMMAND:
267+
return self._create_env_with_config(CONDA_COMMAND, channels)
281268

282269
raise RuntimeError(
283270
"""Failed to create the virtual environment for xeus-python,

0 commit comments

Comments
 (0)
This repository has been archived.