11from pathlib import Path
2- from typing import Any , Optional , Union , List , Sequence , overload
2+ from typing import Any , Optional , Union , List , Tuple , Dict , overload
33from urllib .parse import urlparse
44
55from idom .core .vdom import VdomDict , ImportSourceDict , make_vdom_constructor
@@ -15,20 +15,22 @@ def install(packages: str) -> "Module":
1515
1616
1717@overload
18- def install (packages : Sequence [ str ]) -> List ["Module" ]:
18+ def install (packages : Union [ List [ str ], Tuple [ str ] ]) -> List ["Module" ]:
1919 ...
2020
2121
2222def install (
23- packages : Sequence [str ], ignore_installed : bool = False
23+ packages : Union [str , List [ str ], Tuple [ str ] ], ignore_installed : bool = False
2424) -> Union ["Module" , List ["Module" ]]:
25- return_one = isinstance (packages , str )
26- if return_one :
25+ if isinstance (packages , str ):
2726 packages = [packages ]
27+ return_one = True
28+ else :
29+ return_one = False
2830
2931 pkg_names = {get_package_name (pkg ) for pkg in packages }
3032
31- if pkg_names .difference (client .current .web_module_names ()):
33+ if ignore_installed or pkg_names .difference (client .current .web_module_names ()):
3234 builtin_client .build (packages )
3335 not_discovered = pkg_names .difference (client .current .web_module_names ())
3436 if not_discovered :
@@ -37,10 +39,7 @@ def install(
3739 f"{ client .current } failed to discover { list (not_discovered )} ."
3840 )
3941
40- if return_one :
41- return Module (pkg_names .pop ())
42- else :
43- return list (map (Module , pkg_names ))
42+ return Module (pkg_names .pop ()) if return_one else [Module (pkg ) for pkg in pkg_names ]
4443
4544
4645class Module :
@@ -77,7 +76,11 @@ def __init__(
7776 self .fallback = fallback
7877 self .exports : Optional [List [str ]] = None
7978 if source_file is not None :
80- self .url = client .current .add_web_module (url_or_name , source_file )
79+ self .url = (
80+ client .current .web_module_url (url_or_name )
81+ if client .current .web_module_exists (url_or_name )
82+ else client .current .add_web_module (url_or_name , source_file )
83+ )
8184 if check_exports :
8285 self .exports = client .current .web_module_exports (url_or_name )
8386 elif client .current .web_module_exists (url_or_name ):
@@ -86,14 +89,10 @@ def __init__(
8689 self .exports = client .current .web_module_exports (url_or_name )
8790 elif _is_url (url_or_name ):
8891 self .url = url_or_name
89- self .installed = False
9092 else :
91- raise ValueError (
92- f"{ url_or_name !r} is not installed or is not a URL - "
93- "only installed modules can omit a file extension."
94- )
93+ raise ValueError (f"{ url_or_name !r} is not installed or is not a URL" )
9594
96- def use (
95+ def define (
9796 self ,
9897 name : str ,
9998 has_children : bool = True ,
@@ -161,7 +160,7 @@ def __call__(
161160 return self ._constructor (import_source = self ._import_source , * args , ** kwargs )
162161
163162 def __repr__ (self ) -> str :
164- info = {"name" : self ._name , ** self ._import_source }
163+ info : Dict [ str , Any ] = {"name" : self ._name , ** self ._import_source }
165164 strings = ", " .join (f"{ k } ={ v !r} " for k , v in info .items ())
166165 return f"{ type (self ).__name__ } ({ strings } )"
167166
0 commit comments