Skip to content

Commit 4e2c23e

Browse files
committed
error if no files
1 parent c630bdc commit 4e2c23e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/idom/_console/update_html_usages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import click
1616

1717
from idom import html
18+
from idom._console.utils import error
1819

1920

2021
CAMEL_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

6371
def generate_rewrite(file: Path, source: str) -> str | None:
6472
tree = ast.parse(source)

src/idom/_console/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import click
2+
3+
4+
def error(text: str) -> None:
5+
click.echo(f"{click.style('Error', fg='red')}: {text}")

tests/test__console/test_update_html_usages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
[

0 commit comments

Comments
 (0)