File tree 2 files changed +29
-8
lines changed
2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -60,14 +60,20 @@ def add_web_module(
60
60
source : Union [Path , str ],
61
61
) -> None :
62
62
"""Add a web module from source"""
63
- if web_module_exists (package_name ):
64
- raise ValueError (f"Web module { package_name !r} already exists" )
65
- source = Path (source )
66
- if not source .exists ():
63
+ resolved_source = Path (source ).resolve ()
64
+ if not resolved_source .exists ():
67
65
raise FileNotFoundError (f"Package source file does not exist: { str (source )!r} " )
68
66
target = web_module_path (package_name )
67
+ if target .resolve () == resolved_source :
68
+ return None # already added
69
69
target .parent .mkdir (parents = True , exist_ok = True )
70
- target .symlink_to (source .absolute ())
70
+ # this will raise an error if already exists
71
+ target .symlink_to (resolved_source )
72
+
73
+
74
+ def remove_web_module (package_name : str , must_exist : bool = False ) -> None :
75
+ """Remove a web module"""
76
+ web_module_path (package_name , must_exist ).unlink ()
71
77
72
78
73
79
def restore () -> None :
Original file line number Diff line number Diff line change 4
4
from idom .client .manage import (
5
5
add_web_module ,
6
6
build ,
7
+ remove_web_module ,
7
8
restore ,
8
9
web_module_exists ,
9
10
web_module_exports ,
@@ -31,11 +32,25 @@ def test_add_web_module_source_must_exist(tmp_path):
31
32
32
33
33
34
def test_cannot_add_web_module_if_already_exists (tmp_path ):
35
+ first_temp_file = tmp_path / "temp-1.js"
36
+ second_temp_file = tmp_path / "temp-2.js"
37
+
38
+ first_temp_file .write_text ("console.log('hello!')" ) # this won't get run
39
+ second_temp_file .write_text ("console.log('hello!')" ) # this won't get run
40
+
41
+ add_web_module ("test" , first_temp_file )
42
+ with pytest .raises (FileExistsError ):
43
+ add_web_module ("test" , second_temp_file )
44
+
45
+ remove_web_module ("test" )
46
+
47
+
48
+ def test_can_add_web_module_if_already_exists_and_source_is_same (tmp_path ):
34
49
temp_file = tmp_path / "temp.js"
35
- temp_file .write_text ("console.log('hello!')" ) # this won't get run
50
+ temp_file .write_text ("console.log('hello!')" )
51
+ add_web_module ("test" , temp_file )
36
52
add_web_module ("test" , temp_file )
37
- with pytest .raises (ValueError , match = "already exists" ):
38
- add_web_module ("test" , temp_file )
53
+ remove_web_module ("test" )
39
54
40
55
41
56
def test_web_module_path_must_exist ():
You can’t perform that action at this time.
0 commit comments