Skip to content

Commit d2931ef

Browse files
authored
Micromamba dependency and proper prefix relocation (#200)
* Always assume micromamba * Prefix relocation using micromamba * Fixup * Without relocation for now * Relocate prefix * Try * Try * Fix
1 parent 07b1215 commit d2931ef

File tree

3 files changed

+16
-148
lines changed

3 files changed

+16
-148
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -87,62 +87,7 @@ jobs:
8787
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/xeus.*OK"
8888
python -m jupyterlab.browser_check --no-browser-test
8989
90-
python-tests-mamba-python:
91-
needs: build
92-
runs-on: ubuntu-latest
93-
94-
steps:
95-
- name: Checkout
96-
uses: actions/checkout@v4
97-
98-
- uses: actions/download-artifact@v4
99-
with:
100-
name: extension-artifacts
101-
102-
- name: Install Conda environment with Micromamba
103-
uses: mamba-org/setup-micromamba@v2
104-
with:
105-
environment-file: environment-dev.yaml
106-
107-
- name: Make sure the Mamba Python API is available
108-
run: |
109-
python -c "from mamba.api import create"
110-
111-
- name: Install
112-
run: pip install jupyterlite_xeus*.whl
113-
114-
- name: Run tests
115-
run: pytest -rP test_xeus.py
116-
working-directory: tests
117-
118-
python-tests-mamba:
119-
needs: build
120-
runs-on: ubuntu-latest
121-
122-
steps:
123-
- name: Checkout
124-
uses: actions/checkout@v4
125-
126-
- uses: actions/download-artifact@v4
127-
with:
128-
name: extension-artifacts
129-
130-
- name: Install Conda environment with Micromamba
131-
uses: mamba-org/setup-micromamba@v2
132-
with:
133-
environment-file: environment-dev.yaml
134-
135-
- name: Install mamba
136-
run: conda install -c conda-forge mamba
137-
138-
- name: Install
139-
run: pip install jupyterlite_xeus*.whl
140-
141-
- name: Run tests
142-
run: pytest -rP test_xeus.py
143-
working-directory: tests
144-
145-
python-tests-micromamba:
90+
python-tests:
14691
needs: build
14792
runs-on: ubuntu-latest
14893

@@ -167,30 +112,6 @@ jobs:
167112
run: pytest -rP test_xeus.py
168113
working-directory: tests
169114

170-
python-tests-conda:
171-
needs: build
172-
runs-on: ubuntu-latest
173-
174-
steps:
175-
- name: Checkout
176-
uses: actions/checkout@v4
177-
178-
- uses: actions/download-artifact@v4
179-
with:
180-
name: extension-artifacts
181-
182-
- name: Install Conda environment with Micromamba
183-
uses: mamba-org/setup-micromamba@v2
184-
with:
185-
environment-file: environment-dev.yaml
186-
187-
- name: Install
188-
run: pip install jupyterlite_xeus*.whl
189-
190-
- name: Run tests
191-
run: pytest -rP test_xeus.py
192-
working-directory: tests
193-
194115
integration-tests:
195116
name: Integration tests
196117
needs: build

jupyterlite_xeus/create_conda_env.py

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@
66

77
from ._pip import _install_pip_dependencies
88

9-
try:
10-
from mamba.api import create as mamba_create
11-
12-
MAMBA_PYTHON_AVAILABLE = True
13-
except ImportError:
14-
MAMBA_PYTHON_AVAILABLE = False
15-
16-
MAMBA_COMMAND = shutil.which("mamba")
179
MICROMAMBA_COMMAND = shutil.which("micromamba")
18-
CONDA_COMMAND = shutil.which("conda")
1910
PLATFORM = "emscripten-wasm32"
2011

2112

@@ -85,76 +76,32 @@ def _create_conda_env_from_specs_impl(env_name, root_prefix, specs, channels):
8576

8677
Path(root_prefix).mkdir(parents=True, exist_ok=True)
8778

88-
if MAMBA_PYTHON_AVAILABLE:
89-
mamba_create(
90-
env_name=env_name,
91-
base_prefix=root_prefix,
92-
specs=specs,
93-
channels=channels,
94-
target_platform=PLATFORM,
95-
)
96-
return
97-
9879
channels_args = []
9980
for channel in channels:
10081
channels_args.extend(["-c", channel])
10182

102-
if MICROMAMBA_COMMAND:
103-
subprocess_run(
104-
[
105-
MICROMAMBA_COMMAND,
106-
"create",
107-
"--yes",
108-
"--no-pyc",
109-
"--root-prefix",
110-
root_prefix,
111-
"--name",
112-
env_name,
113-
f"--platform={PLATFORM}",
114-
*channels_args,
115-
*specs,
116-
],
117-
check=True,
118-
)
119-
return
120-
121-
if MAMBA_COMMAND:
122-
# Mamba needs the directory to exist already
123-
prefix_path.mkdir(parents=True, exist_ok=True)
124-
return _create_env_with_config(MAMBA_COMMAND, prefix_path, specs, channels_args)
83+
if not MICROMAMBA_COMMAND:
84+
raise RuntimeError("""
85+
micromamba is needed for creating the emscripten environment.
86+
Please install it using conda `conda install micromamba -c conda-forge` or
87+
from https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html
88+
""")
12589

126-
if CONDA_COMMAND:
127-
return _create_env_with_config(CONDA_COMMAND, prefix_path, specs, channels_args)
128-
129-
raise RuntimeError(
130-
"""Failed to create the virtual environment for xeus-python,
131-
please make sure at least mamba, micromamba or conda is installed.
132-
"""
133-
)
134-
135-
136-
def _create_env_with_config(conda, prefix_path, specs, channels_args):
137-
subprocess_run(
138-
[conda, "create", "--yes", "--prefix", prefix_path, *channels_args],
139-
check=True,
140-
)
141-
_create_config(prefix_path)
14290
subprocess_run(
14391
[
144-
conda,
145-
"install",
92+
MICROMAMBA_COMMAND,
93+
"create",
14694
"--yes",
95+
"--no-pyc",
14796
"--prefix",
14897
prefix_path,
98+
"--relocate-prefix",
99+
"",
100+
"--root-prefix",
101+
root_prefix,
102+
f"--platform={PLATFORM}",
149103
*channels_args,
150104
*specs,
151105
],
152106
check=True,
153-
env=os.environ.copy(),
154107
)
155-
156-
157-
def _create_config(prefix_path):
158-
with open(prefix_path / ".condarc", "w") as fobj:
159-
fobj.write(f"subdir: {PLATFORM}")
160-
os.environ["CONDARC"] = str(prefix_path / ".condarc")

tests/test_xeus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_mount_point():
9393
]
9494

9595
for step in addon.post_build(manager):
96-
pass
96+
pass
9797

9898
outpath = Path(addon.cwd_name) / "packed_env" / "xpython"
9999

0 commit comments

Comments
 (0)