Skip to content

Commit

Permalink
use a list for piplite_urls (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl authored Jan 17, 2025
1 parent 0f9673d commit dffb813
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
20 changes: 14 additions & 6 deletions jupyterlite_pyodide_kernel/addons/piplite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import urllib.parse
from hashlib import md5, sha256
from pathlib import Path
from typing import Tuple as _Tuple
from typing import List as _List

import doit.tools
from jupyterlite_core.constants import (
Expand All @@ -16,8 +16,7 @@
LAB_EXTENSIONS,
UTF8,
)
from jupyterlite_core.trait_types import TypedTuple
from traitlets import Unicode
from traitlets import List

from ._base import _BaseAddon

Expand All @@ -37,8 +36,7 @@ class PipliteAddon(_BaseAddon):
__all__ = ["post_init", "build", "post_build", "check"]

# traits
piplite_urls: _Tuple[str] = TypedTuple(
Unicode(),
piplite_urls: _List[str] = List(
help="Local paths or URLs of piplite-compatible wheels to copy and index",
).tag(config=True)

Expand Down Expand Up @@ -84,8 +82,18 @@ def settings_schema(self):

def post_init(self, manager):
"""handle downloading of wheels"""
task_names = []
for path_or_url in self.piplite_urls:
yield from self.resolve_one_wheel(path_or_url)
for task in self.resolve_one_wheel(path_or_url):
if task["name"] in task_names:
self.log.warning(
"[piplite] skipping-already scheduled wheel task %s: %s",
task["name"],
task["targets"],
)
continue
yield task
task_names += [task["name"]]

def build(self, manager):
"""yield a doit task to copy each local wheel into the output_dir"""
Expand Down
29 changes: 20 additions & 9 deletions jupyterlite_pyodide_kernel/tests/test_piplite.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@
from .conftest import WHEELS, PYODIDE_KERNEL_EXTENSION


def has_wheel_after_build(an_empty_lite_dir, script_runner):
def has_wheel_after_build(an_empty_lite_dir, script_runner, cli_args=None):
"""run a build, expecting the fixture wheel to be there"""
build = script_runner.run(["jupyter", "lite", "build"], cwd=str(an_empty_lite_dir))
cli_args = cli_args or []
build = script_runner.run(
["jupyter", "lite", "build", *cli_args], cwd=str(an_empty_lite_dir)
)
assert build.success

check = script_runner.run(["jupyter", "lite", "check"], cwd=str(an_empty_lite_dir))
check = script_runner.run(
["jupyter", "lite", "check", *cli_args], cwd=str(an_empty_lite_dir)
)
assert check.success

output = an_empty_lite_dir / "_output"
Expand All @@ -47,12 +52,13 @@ def has_wheel_after_build(an_empty_lite_dir, script_runner):
assert WHEELS[0].name in wheel_index_text, wheel_index_text


@mark.parametrize("by_cli", [0, 1, 2])
@mark.parametrize(
"remote,folder",
[[True, False], [False, False], [False, True]],
)
def test_piplite_urls(
an_empty_lite_dir, script_runner, remote, folder, a_fixture_server
by_cli, remote, folder, an_empty_lite_dir, script_runner, a_fixture_server
):
"""can we include a single wheel?"""
ext = WHEELS[0]
Expand All @@ -75,15 +81,20 @@ def test_piplite_urls(
"federated_extensions": [
str(PYODIDE_KERNEL_EXTENSION),
],
},
"PipliteAddon": {
"piplite_urls": piplite_urls,
},
}
}

if by_cli == 0:
cli_args = []
config.update(PipliteAddon={"piplite_urls": piplite_urls})
elif by_cli == 1:
cli_args = ["--piplite-wheels", piplite_urls[0]]
elif by_cli == 2:
cli_args = ["--piplite-wheels", piplite_urls[0], "--piplite-wheels", "."]

(an_empty_lite_dir / "jupyter_lite_config.json").write_text(json.dumps(config))

has_wheel_after_build(an_empty_lite_dir, script_runner)
has_wheel_after_build(an_empty_lite_dir, script_runner, cli_args)


def test_lite_dir_wheel(an_empty_lite_dir, script_runner):
Expand Down

0 comments on commit dffb813

Please sign in to comment.