@@ -10,60 +10,42 @@ class Module:
10
10
11
11
Parameters:
12
12
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.
20
16
source:
21
17
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.
22
22
23
23
Returns:
24
24
An :class:`Import` element for the newly defined module.
25
25
"""
26
26
27
- __slots__ = ( "_module" , "_name" , " _installed")
27
+ __slots__ = "_module" , "_installed"
28
28
29
29
def __init__ (
30
30
self ,
31
31
name : str ,
32
- install : Union [bool , str ] = False ,
33
32
source : Optional [Union [str , Path ]] = None ,
34
33
replace : bool = False ,
35
34
) -> None :
36
35
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 )
44
39
self ._module = client .register_web_module (name , source )
45
40
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
57
41
elif client .web_module_exists (name ):
58
42
self ._module = client .web_module_url (name )
59
43
else :
60
44
self ._module = name
61
45
62
46
@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
67
49
68
50
@property
69
51
def url (self ) -> str :
@@ -72,11 +54,6 @@ def url(self) -> str:
72
54
def Import (self , name : str , * args : Any , ** kwargs : Any ) -> "Import" :
73
55
return Import (self ._module , name , * args , ** kwargs )
74
56
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
-
80
57
def __repr__ (self ) -> str : # pragma: no cover
81
58
return f"{ type (self ).__name__ } ({ self ._module !r} )"
82
59
0 commit comments