From dffb8132cc3700eaaf75aa1ad39d925e8f3f2a2a Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Fri, 17 Jan 2025 12:18:37 -0500 Subject: [PATCH] use a list for piplite_urls (#161) --- jupyterlite_pyodide_kernel/addons/piplite.py | 20 +++++++++---- .../tests/test_piplite.py | 29 +++++++++++++------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/jupyterlite_pyodide_kernel/addons/piplite.py b/jupyterlite_pyodide_kernel/addons/piplite.py index acf3adb4..e90dadb2 100644 --- a/jupyterlite_pyodide_kernel/addons/piplite.py +++ b/jupyterlite_pyodide_kernel/addons/piplite.py @@ -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 ( @@ -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 @@ -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) @@ -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""" diff --git a/jupyterlite_pyodide_kernel/tests/test_piplite.py b/jupyterlite_pyodide_kernel/tests/test_piplite.py index 643347ce..a1571e4e 100644 --- a/jupyterlite_pyodide_kernel/tests/test_piplite.py +++ b/jupyterlite_pyodide_kernel/tests/test_piplite.py @@ -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" @@ -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] @@ -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):