mirror of
https://github.com/esphome/esphome.git
synced 2026-05-23 03:06:05 +08:00
[core] Improve clean-all with no arguments (#15184)
This commit is contained in:
@@ -476,6 +476,16 @@ def clean_all(configuration: list[str]):
|
||||
data_dirs.append(Path(env_data_dir))
|
||||
if env_build_path := os.environ.get("ESPHOME_BUILD_PATH"):
|
||||
data_dirs.append(Path(env_build_path))
|
||||
if not data_dirs:
|
||||
# No config files or known data dirs, check current directory
|
||||
cwd_esphome = Path.cwd() / ".esphome"
|
||||
if cwd_esphome.is_dir():
|
||||
data_dirs.append(cwd_esphome)
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"No configuration files specified and no .esphome directory found in current directory. "
|
||||
"Pass YAML files or a configuration directory to clean build artifacts."
|
||||
)
|
||||
|
||||
# Clean build dir
|
||||
for dir in data_dirs:
|
||||
|
||||
@@ -990,6 +990,47 @@ def test_clean_all_ignores_empty_env_vars(
|
||||
assert marker.exists()
|
||||
|
||||
|
||||
@patch("esphome.writer.CORE")
|
||||
def test_clean_all_no_args_with_esphome_dir(
|
||||
mock_core: MagicMock,
|
||||
tmp_path: Path,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test clean_all with no args cleans .esphome in cwd."""
|
||||
esphome_dir = tmp_path / ".esphome"
|
||||
esphome_dir.mkdir()
|
||||
(esphome_dir / "dummy.txt").write_text("x")
|
||||
|
||||
from esphome.writer import clean_all
|
||||
|
||||
with (
|
||||
caplog.at_level("INFO"),
|
||||
patch("esphome.writer.Path.cwd", return_value=tmp_path),
|
||||
):
|
||||
clean_all([])
|
||||
|
||||
assert esphome_dir.exists()
|
||||
assert not (esphome_dir / "dummy.txt").exists()
|
||||
|
||||
|
||||
@patch("esphome.writer.CORE")
|
||||
def test_clean_all_no_args_no_esphome_dir(
|
||||
mock_core: MagicMock,
|
||||
tmp_path: Path,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test clean_all with no args and no .esphome dir warns."""
|
||||
from esphome.writer import clean_all
|
||||
|
||||
with (
|
||||
caplog.at_level("WARNING"),
|
||||
patch("esphome.writer.Path.cwd", return_value=tmp_path),
|
||||
):
|
||||
clean_all([])
|
||||
|
||||
assert "No configuration files specified" in caplog.text
|
||||
|
||||
|
||||
@patch("esphome.writer.CORE")
|
||||
def test_clean_all(
|
||||
mock_core: MagicMock,
|
||||
|
||||
Reference in New Issue
Block a user