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

Compute local package dir when pip install #142

Merged
merged 5 commits into from
Jul 25, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions jupyterlite_xeus_python/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ def build_and_pack_emscripten_env(

# Process environment.yml file
if environment_file and Path(environment_file).exists():
env_file = Path(environment_file)

bail_early = False

with open(Path(environment_file)) as f:
with open(env_file) as f:
env_data = yaml.safe_load(f)

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

# Bail early if there is nothing to do
if bail_early and not force:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_package/environment-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: xeus-python-kernel-3
channels:
- https://repo.mamba.pm/emscripten-forge
- https://repo.mamba.pm/conda-forge
dependencies:
- numpy
- pip:
- .
3 changes: 3 additions & 0 deletions tests/test_package/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[project]
name = "test-package"
version = "0.1.0"
Empty file.
1 change: 1 addition & 0 deletions tests/test_package/test_package/hey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('Hey')
22 changes: 22 additions & 0 deletions tests/test_xeus_python_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ def test_python_env_from_file_1():
os.remove(Path(addon.cwd.name) / "empack_env_meta.json")


def test_python_env_from_file_3():
app = LiteStatusApp(log_level="DEBUG")
app.initialize()
manager = app.lite_manager

addon = XeusPythonEnv(manager)
addon.environment_file = "test_package/environment-3.yml"

for step in addon.post_build(manager):
pass

# Test
assert os.path.isdir(
"/tmp/xeus-python-kernel/envs/xeus-python-kernel-3/lib/python3.10/site-packages/test_package"
)
assert os.path.isfile(
"/tmp/xeus-python-kernel/envs/xeus-python-kernel-3/lib/python3.10/site-packages/test_package/hey.py"
)

os.remove(Path(addon.cwd.name) / "empack_env_meta.json")


def test_python_env_from_file_2():
app = LiteStatusApp(log_level="DEBUG")
app.initialize()
Expand Down