Skip to content

Commit a4a50cc

Browse files
committed
remove ability to install modules at runtime via idom.Module
1 parent 522b5a9 commit a4a50cc

File tree

2 files changed

+19
-65
lines changed

2 files changed

+19
-65
lines changed

Diff for: idom/widgets/module.py

+13-36
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,42 @@ class Module:
1010
1111
Parameters:
1212
name:
13-
The module's name. If ``install`` or ``source`` are provided omit the ``.js``
14-
file extension. Otherwise this is the exact import path and could be anything
15-
including a URL.
16-
install:
17-
If a string, then the dependency string used to install a module with
18-
the given ``name`` (e.g. ``[email protected]``). If ``True`` then the given
19-
``name`` will be used as the dependency string.
13+
If the module is installed, or ``source`` is not None, then this is the name
14+
the the module to import from (omit the ``.js`` file extension). Otherwise
15+
this is the URl (relative or absolute) to import from.
2016
source:
2117
Create a module of the given name using the given source code.
18+
replace:
19+
Overwrite a module defined from ``source`` if one of the same ``name``
20+
already exists, otherwise raise a ``ValueError`` complaining of name
21+
conflict.
2222
2323
Returns:
2424
An :class:`Import` element for the newly defined module.
2525
"""
2626

27-
__slots__ = ("_module", "_name", "_installed")
27+
__slots__ = "_module", "_installed"
2828

2929
def __init__(
3030
self,
3131
name: str,
32-
install: Union[bool, str] = False,
3332
source: Optional[Union[str, Path]] = None,
3433
replace: bool = False,
3534
) -> None:
3635
self._installed = False
37-
if install and source:
38-
raise ValueError("Both 'install' and 'source' were given.")
39-
elif (install or source) and not replace and client.web_module_exists(name):
40-
self._module = client.web_module_url(name)
41-
self._installed = True
42-
self._name = name
43-
elif source is not None:
36+
if source is not None:
37+
if replace:
38+
client.delete_web_modules([name], skip_missing=True)
4439
self._module = client.register_web_module(name, source)
4540
self._installed = True
46-
self._name = name
47-
elif isinstance(install, str):
48-
client.install([install], [name])
49-
self._module = client.web_module_url(name)
50-
self._installed = True
51-
self._name = name
52-
elif install is True:
53-
client.install(name)
54-
self._module = client.web_module_url(name)
55-
self._installed = True
56-
self._name = name
5741
elif client.web_module_exists(name):
5842
self._module = client.web_module_url(name)
5943
else:
6044
self._module = name
6145

6246
@property
63-
def name(self) -> str:
64-
if not self._installed:
65-
raise ValueError("Module is not installed locally")
66-
return self._name
47+
def installed(self) -> bool:
48+
return self._installed
6749

6850
@property
6951
def url(self) -> str:
@@ -72,11 +54,6 @@ def url(self) -> str:
7254
def Import(self, name: str, *args: Any, **kwargs: Any) -> "Import":
7355
return Import(self._module, name, *args, **kwargs)
7456

75-
def delete(self) -> None:
76-
if not self._installed:
77-
raise ValueError("Module is not installed locally")
78-
client.delete_web_modules([self._name])
79-
8057
def __repr__(self) -> str: # pragma: no cover
8158
return f"{type(self).__name__}({self._module!r})"
8259

Diff for: tests/test_widgets/test_module.py

+6-29
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,23 @@ def test_module_cannot_have_source_and_install():
1616

1717
@pytest.fixture
1818
def victory():
19-
yield Module("victory", install=True)
19+
if "victory" not in client.installed():
20+
client.install(["victory"], [])
21+
return Module("victory")
2022

2123

2224
@pytest.mark.slow
23-
def test_install(driver, display, victory):
25+
def test_installed_module(driver, display, victory):
26+
assert victory.installed
2427
display(victory.Import("VictoryBar"))
25-
2628
driver.find_element_by_class_name("VictoryContainer")
2729

28-
assert client.web_module_exists("victory")
29-
assert client.web_module_url("victory") == "../web_modules/victory.js"
30-
3130

3231
@pytest.mark.slow
3332
def test_reference_pre_installed_module(victory):
3433
assert victory.url == idom.Module("victory").url
3534

3635

37-
@pytest.mark.slow
38-
def test_delete_module(victory):
39-
victory.delete()
40-
assert not client.web_module_exists("victory")
41-
42-
with pytest.raises(ValueError, match="does not exist"):
43-
victory.delete()
44-
45-
4636
@pytest.mark.slow
4737
def test_custom_module(driver, display, victory):
4838
my_chart = Module("my/chart", source=HERE / "my_chart.js")
@@ -59,21 +49,8 @@ def test_custom_module(driver, display, victory):
5949
assert not client.web_module_exists("my/chart")
6050

6151

62-
def test_module_deletion():
63-
# also test install
64-
jquery = idom.Module("jquery", install="[email protected]")
65-
assert idom.client.web_module_exists(jquery.name)
66-
with idom.client.web_module_path(jquery.name).open() as f:
67-
assert "jQuery JavaScript Library v3.5.0" in f.read()
68-
jquery.delete()
69-
assert not idom.client.web_module_exists(jquery.name)
70-
71-
7252
def test_module_from_url():
7353
url = "https://code.jquery.com/jquery-3.5.0.js"
7454
jquery = idom.Module(url)
7555
assert jquery.url == url
76-
with pytest.raises(ValueError, match="Module is not installed locally"):
77-
jquery.name
78-
with pytest.raises(ValueError, match="Module is not installed locally"):
79-
jquery.delete()
56+
assert not jquery.installed

0 commit comments

Comments
 (0)