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

Commit 13dc529

Browse files
authored
Compute local package dir when pip install (#142)
* Compute local package dir when pip install * Add test * Fix test * Iterate * Is test order important?
1 parent ba9891f commit 13dc529

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

jupyterlite_xeus_python/build.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ def build_and_pack_emscripten_env(
240240

241241
# Process environment.yml file
242242
if environment_file and Path(environment_file).exists():
243+
env_file = Path(environment_file)
244+
243245
bail_early = False
244246

245-
with open(Path(environment_file)) as f:
247+
with open(env_file) as f:
246248
env_data = yaml.safe_load(f)
247249

248250
if env_data.get("name") is not None:
@@ -260,7 +262,11 @@ def build_and_pack_emscripten_env(
260262
if isinstance(dependency, str) and dependency not in specs:
261263
specs.append(dependency)
262264
elif isinstance(dependency, dict) and dependency.get("pip") is not None:
263-
pip_dependencies = dependency["pip"]
265+
# If it's a local Python package, make its path relative to the environment file
266+
pip_dependencies = [
267+
((env_file.parent / pip_dep).resolve() if os.path.isdir(env_file.parent / pip_dep) else pip_dep)
268+
for pip_dep in dependency["pip"]
269+
]
264270

265271
# Bail early if there is nothing to do
266272
if bail_early and not force:

tests/test_package/environment-3.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: xeus-python-kernel-3
2+
channels:
3+
- https://repo.mamba.pm/emscripten-forge
4+
- https://repo.mamba.pm/conda-forge
5+
dependencies:
6+
- numpy
7+
- pip:
8+
- .

tests/test_package/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[project]
2+
name = "test-package"
3+
version = "0.1.0"

tests/test_package/test_package/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('Hey')

tests/test_xeus_python_env.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ def test_python_env_from_file_1():
9090
os.remove(Path(addon.cwd.name) / "empack_env_meta.json")
9191

9292

93+
def test_python_env_from_file_3():
94+
app = LiteStatusApp(log_level="DEBUG")
95+
app.initialize()
96+
manager = app.lite_manager
97+
98+
addon = XeusPythonEnv(manager)
99+
addon.environment_file = "test_package/environment-3.yml"
100+
101+
for step in addon.post_build(manager):
102+
pass
103+
104+
# Test
105+
assert os.path.isdir(
106+
"/tmp/xeus-python-kernel/envs/xeus-python-kernel-3/lib/python3.10/site-packages/test_package"
107+
)
108+
assert os.path.isfile(
109+
"/tmp/xeus-python-kernel/envs/xeus-python-kernel-3/lib/python3.10/site-packages/test_package/hey.py"
110+
)
111+
112+
os.remove(Path(addon.cwd.name) / "empack_env_meta.json")
113+
114+
93115
def test_python_env_from_file_2():
94116
app = LiteStatusApp(log_level="DEBUG")
95117
app.initialize()

0 commit comments

Comments
 (0)