@@ -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. ``my-module@1.2.3``). 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
0 commit comments