Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad877f2

Browse files
committedJan 5, 2023
Allow pre-installing pip packages
1 parent 0cad1ad commit ad877f2

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed
 

‎docs/environment.yml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ dependencies:
66
- numpy
77
- matplotlib
88
- ipycanvas
9+
- mpmath
10+
- pip:
11+
- git+https://github.com/sympy/sympy

‎jupyterlite_xeus_python/build.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from empack.file_packager import pack_environment
1313
from empack.file_patterns import PkgFileFilter, pkg_file_filter_from_yaml
14+
from empack.filter_env import write_minimal_conda_meta
1415

1516
import typer
1617

@@ -117,6 +118,30 @@ def _create_config(prefix_path):
117118
os.environ["CONDARC"] = str(prefix_path / ".condarc")
118119

119120

121+
def _install_pip_dependencies(prefix_path, dependencies):
122+
# Create a fake conda_meta file for each dependency, this prevents empack from filtering out pip dependencies
123+
for package in dependencies:
124+
# TODO Remove the version specifier from the package name if there is one
125+
write_minimal_conda_meta(
126+
dict(name=package, version="", build="pip", build_number=0),
127+
prefix_path,
128+
)
129+
130+
run(
131+
[
132+
"pip",
133+
"install",
134+
*dependencies,
135+
"--prefix",
136+
prefix_path,
137+
"--no-input",
138+
"--no-deps",
139+
"--verbose",
140+
],
141+
check=True,
142+
)
143+
144+
120145
def build_and_pack_emscripten_env(
121146
python_version: str = PYTHON_VERSION,
122147
xeus_python_version: str = "",
@@ -144,6 +169,8 @@ def build_and_pack_emscripten_env(
144169
if packages or xeus_python_version or environment_file:
145170
bail_early = False
146171

172+
pip_dependencies = []
173+
147174
# Process environment.yml file
148175
if environment_file and Path(environment_file).exists():
149176
bail_early = False
@@ -166,10 +193,7 @@ def build_and_pack_emscripten_env(
166193
if isinstance(dependency, str) and dependency not in specs:
167194
specs.append(dependency)
168195
elif isinstance(dependency, dict) and dependency.get("pip") is not None:
169-
raise RuntimeError(
170-
"""Cannot install pip dependencies in the xeus-python Emscripten environment (yet?).
171-
"""
172-
)
196+
pip_dependencies = dependency["pip"]
173197

174198
# Bail early if there is nothing to do
175199
if bail_early and not force:
@@ -190,6 +214,10 @@ def build_and_pack_emscripten_env(
190214
# Create emscripten env with the given packages
191215
create_env(env_name, root_prefix, specs, channels)
192216

217+
# Install pip dependencies
218+
if pip_dependencies:
219+
_install_pip_dependencies(prefix_path, pip_dependencies)
220+
193221
pack_kwargs = {}
194222

195223
# Download env filter config

0 commit comments

Comments
 (0)
This repository has been archived.