File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 15
15
import click
16
16
17
17
from idom import html
18
+ from idom ._console .utils import error
18
19
19
20
20
21
CAMEL_CASE_SUB_PATTERN = re .compile (r"(?<!^)(?=[A-Z])" )
@@ -53,12 +54,19 @@ def update_html_usages(directories: list[str]) -> None:
53
54
"""
54
55
if sys .version_info < (3 , 9 ): # pragma: no cover
55
56
raise RuntimeError ("This command requires Python>=3.9" )
57
+
58
+ at_leat_one_file = False
56
59
for d in directories :
57
60
for file in Path (d ).rglob ("*.py" ):
61
+ at_leat_one_file = True
58
62
result = generate_rewrite (file = file , source = file .read_text ())
59
63
if result is not None :
60
64
file .write_text (result )
61
65
66
+ if not at_leat_one_file :
67
+ error ("Found no Python files in the given directories." )
68
+ sys .exit (1 )
69
+
62
70
63
71
def generate_rewrite (file : Path , source : str ) -> str | None :
64
72
tree = ast .parse (source )
Original file line number Diff line number Diff line change
1
+ import click
2
+
3
+
4
+ def error (text : str ) -> None :
5
+ click .echo (f"{ click .style ('Error' , fg = 'red' )} : { text } " )
Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ def test_update_html_usages(tmp_path):
27
27
assert tempfile .read_text () == "html.div(class_name=test)"
28
28
29
29
30
+ def test_update_html_usages_no_files (tmp_path ):
31
+ runner = CliRunner ()
32
+
33
+ result = runner .invoke (update_html_usages , "directory-does-no-exist" )
34
+ assert result .exit_code == 1
35
+ assert "Found no Python files" in result .stdout
36
+
37
+
30
38
@pytest .mark .parametrize (
31
39
"source, expected" ,
32
40
[
You can’t perform that action at this time.
0 commit comments