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 1515import click
1616
1717from idom import html
18+ from idom ._console .utils import error
1819
1920
2021CAMEL_CASE_SUB_PATTERN = re .compile (r"(?<!^)(?=[A-Z])" )
@@ -53,12 +54,19 @@ def update_html_usages(directories: list[str]) -> None:
5354 """
5455 if sys .version_info < (3 , 9 ): # pragma: no cover
5556 raise RuntimeError ("This command requires Python>=3.9" )
57+
58+ at_leat_one_file = False
5659 for d in directories :
5760 for file in Path (d ).rglob ("*.py" ):
61+ at_leat_one_file = True
5862 result = generate_rewrite (file = file , source = file .read_text ())
5963 if result is not None :
6064 file .write_text (result )
6165
66+ if not at_leat_one_file :
67+ error ("Found no Python files in the given directories." )
68+ sys .exit (1 )
69+
6270
6371def generate_rewrite (file : Path , source : str ) -> str | None :
6472 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):
2727 assert tempfile .read_text () == "html.div(class_name=test)"
2828
2929
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+
3038@pytest .mark .parametrize (
3139 "source, expected" ,
3240 [
You can’t perform that action at this time.
0 commit comments