Skip to content

Commit 9881914

Browse files
committed
fix non-deterministic return order in install()
1 parent c77f338 commit 9881914

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/idom/client/module.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pathlib import Path
24
from typing import Any, Dict, List, Optional, Tuple, Union, overload
35
from urllib.parse import urlparse
@@ -12,7 +14,7 @@ def install(
1214
packages: str,
1315
ignore_installed: bool,
1416
fallback: Optional[str],
15-
) -> "Module":
17+
) -> Module:
1618
...
1719

1820

@@ -21,30 +23,29 @@ def install(
2123
packages: Union[List[str], Tuple[str]],
2224
ignore_installed: bool,
2325
fallback: Optional[str],
24-
) -> List["Module"]:
26+
) -> List[Module]:
2527
...
2628

2729

2830
def install(
2931
packages: Union[str, List[str], Tuple[str]],
3032
ignore_installed: bool = False,
3133
fallback: Optional[str] = None,
32-
) -> Union["Module", List["Module"]]:
34+
) -> Union[Module, List[Module]]:
3335
return_one = False
3436
if isinstance(packages, str):
3537
packages = [packages]
3638
return_one = True
3739

38-
pkg_names = {_private.get_package_name(pkg) for pkg in packages}
40+
pkg_names = [_private.get_package_name(pkg) for pkg in packages]
3941

40-
if ignore_installed or pkg_names.difference(manage.web_module_names()):
42+
if ignore_installed or set(pkg_names).difference(manage.web_module_names()):
4143
manage.build(packages, clean_build=False)
4244

43-
return (
44-
Module(pkg_names.pop(), fallback=fallback)
45-
if return_one
46-
else [Module(pkg, fallback=fallback) for pkg in pkg_names]
47-
)
45+
if return_one:
46+
return Module(pkg_names[0], fallback=fallback)
47+
else:
48+
return [Module(pkg, fallback=fallback) for pkg in pkg_names]
4849

4950

5051
class Module:

tests/test_client/test_module.py

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def test_module_import_repr():
2424
)
2525

2626

27+
def test_install_multiple():
28+
# install several random JS packages
29+
pad_left, decamelize, is_sorted = idom.install(
30+
["pad-left", "decamelize", "is-sorted"]
31+
)
32+
# ensure the output order is the same as the input order
33+
assert pad_left.url.endswith("pad-left.js")
34+
assert decamelize.url.endswith("decamelize.js")
35+
assert is_sorted.url.endswith("is-sorted.js")
36+
37+
2738
def test_module_does_not_exist():
2839
with pytest.raises(ValueError, match="is not installed or is not a URL"):
2940
Module("this-module-does-not-exist")

0 commit comments

Comments
 (0)