mirror of
https://github.com/esphome/esphome.git
synced 2025-11-17 07:15:48 +00:00
preen
This commit is contained in:
@@ -756,7 +756,8 @@ def resolve_auto_load(
|
|||||||
return auto_load()
|
return auto_load()
|
||||||
|
|
||||||
|
|
||||||
def _get_components_graph_cache_key() -> str:
|
@cache
|
||||||
|
def get_components_graph_cache_key() -> str:
|
||||||
"""Generate cache key based on all component __init__.py file hashes.
|
"""Generate cache key based on all component __init__.py file hashes.
|
||||||
|
|
||||||
Uses git ls-files with sha1 hashes to generate a stable cache key that works
|
Uses git ls-files with sha1 hashes to generate a stable cache key that works
|
||||||
@@ -807,7 +808,7 @@ def create_components_graph() -> dict[str, list[str]]:
|
|||||||
# Verify cache version matches
|
# Verify cache version matches
|
||||||
if cached_data.get("_version") == COMPONENTS_GRAPH_CACHE_VERSION:
|
if cached_data.get("_version") == COMPONENTS_GRAPH_CACHE_VERSION:
|
||||||
# Verify cache is for current component state
|
# Verify cache is for current component state
|
||||||
cache_key = _get_components_graph_cache_key()
|
cache_key = get_components_graph_cache_key()
|
||||||
if cached_data.get("_cache_key") == cache_key:
|
if cached_data.get("_cache_key") == cache_key:
|
||||||
return cached_data.get("graph", {})
|
return cached_data.get("graph", {})
|
||||||
# Cache key mismatch - stale cache, rebuild
|
# Cache key mismatch - stale cache, rebuild
|
||||||
@@ -898,7 +899,7 @@ def create_components_graph() -> dict[str, list[str]]:
|
|||||||
# Save to cache with version and cache key for validation
|
# Save to cache with version and cache key for validation
|
||||||
cache_data = {
|
cache_data = {
|
||||||
"_version": COMPONENTS_GRAPH_CACHE_VERSION,
|
"_version": COMPONENTS_GRAPH_CACHE_VERSION,
|
||||||
"_cache_key": _get_components_graph_cache_key(),
|
"_cache_key": get_components_graph_cache_key(),
|
||||||
"graph": components_graph,
|
"graph": components_graph,
|
||||||
}
|
}
|
||||||
cache_file.parent.mkdir(exist_ok=True)
|
cache_file.parent.mkdir(exist_ok=True)
|
||||||
|
|||||||
@@ -543,6 +543,7 @@ def test_main_filters_components_without_tests(
|
|||||||
with (
|
with (
|
||||||
patch.object(determine_jobs, "root_path", str(tmp_path)),
|
patch.object(determine_jobs, "root_path", str(tmp_path)),
|
||||||
patch.object(helpers, "root_path", str(tmp_path)),
|
patch.object(helpers, "root_path", str(tmp_path)),
|
||||||
|
patch.object(helpers, "create_components_graph", return_value={}),
|
||||||
patch("sys.argv", ["determine-jobs.py"]),
|
patch("sys.argv", ["determine-jobs.py"]),
|
||||||
patch.object(
|
patch.object(
|
||||||
determine_jobs,
|
determine_jobs,
|
||||||
@@ -640,6 +641,7 @@ def test_main_detects_components_with_variant_tests(
|
|||||||
with (
|
with (
|
||||||
patch.object(determine_jobs, "root_path", str(tmp_path)),
|
patch.object(determine_jobs, "root_path", str(tmp_path)),
|
||||||
patch.object(helpers, "root_path", str(tmp_path)),
|
patch.object(helpers, "root_path", str(tmp_path)),
|
||||||
|
patch.object(helpers, "create_components_graph", return_value={}),
|
||||||
patch("sys.argv", ["determine-jobs.py"]),
|
patch("sys.argv", ["determine-jobs.py"]),
|
||||||
patch.object(
|
patch.object(
|
||||||
determine_jobs,
|
determine_jobs,
|
||||||
|
|||||||
@@ -1125,7 +1125,7 @@ def test_cache_key_generation(mock_git_output: str) -> None:
|
|||||||
mock_result.stdout = mock_git_output
|
mock_result.stdout = mock_git_output
|
||||||
|
|
||||||
with patch("subprocess.run", return_value=mock_result):
|
with patch("subprocess.run", return_value=mock_result):
|
||||||
key = helpers._get_components_graph_cache_key()
|
key = helpers.get_components_graph_cache_key()
|
||||||
|
|
||||||
# Should be a 64-character hex string (SHA256)
|
# Should be a 64-character hex string (SHA256)
|
||||||
assert len(key) == 64
|
assert len(key) == 64
|
||||||
@@ -1138,8 +1138,8 @@ def test_cache_key_consistent_for_same_files(mock_git_output: str) -> None:
|
|||||||
mock_result.stdout = mock_git_output
|
mock_result.stdout = mock_git_output
|
||||||
|
|
||||||
with patch("subprocess.run", return_value=mock_result):
|
with patch("subprocess.run", return_value=mock_result):
|
||||||
key1 = helpers._get_components_graph_cache_key()
|
key1 = helpers.get_components_graph_cache_key()
|
||||||
key2 = helpers._get_components_graph_cache_key()
|
key2 = helpers.get_components_graph_cache_key()
|
||||||
|
|
||||||
assert key1 == key2
|
assert key1 == key2
|
||||||
|
|
||||||
@@ -1153,10 +1153,10 @@ def test_cache_key_different_for_changed_files() -> None:
|
|||||||
mock_result2.stdout = "100644 xyz789... 0 esphome/components/wifi/__init__.py\n"
|
mock_result2.stdout = "100644 xyz789... 0 esphome/components/wifi/__init__.py\n"
|
||||||
|
|
||||||
with patch("subprocess.run", return_value=mock_result1):
|
with patch("subprocess.run", return_value=mock_result1):
|
||||||
key1 = helpers._get_components_graph_cache_key()
|
key1 = helpers.get_components_graph_cache_key()
|
||||||
|
|
||||||
with patch("subprocess.run", return_value=mock_result2):
|
with patch("subprocess.run", return_value=mock_result2):
|
||||||
key2 = helpers._get_components_graph_cache_key()
|
key2 = helpers.get_components_graph_cache_key()
|
||||||
|
|
||||||
assert key1 != key2
|
assert key1 != key2
|
||||||
|
|
||||||
@@ -1167,7 +1167,7 @@ def test_cache_key_uses_git_ls_files(mock_git_output: str) -> None:
|
|||||||
mock_result.stdout = mock_git_output
|
mock_result.stdout = mock_git_output
|
||||||
|
|
||||||
with patch("subprocess.run", return_value=mock_result) as mock_run:
|
with patch("subprocess.run", return_value=mock_result) as mock_run:
|
||||||
helpers._get_components_graph_cache_key()
|
helpers.get_components_graph_cache_key()
|
||||||
|
|
||||||
# Verify git ls-files was called with correct arguments
|
# Verify git ls-files was called with correct arguments
|
||||||
mock_run.assert_called_once()
|
mock_run.assert_called_once()
|
||||||
@@ -1203,7 +1203,7 @@ def test_cache_hit_returns_cached_graph(tmp_path: Path, mock_git_output: str) ->
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
patch("subprocess.run", return_value=mock_result),
|
patch("subprocess.run", return_value=mock_result),
|
||||||
patch("helpers._get_components_graph_cache_key", return_value=cache_key),
|
patch("helpers.get_components_graph_cache_key", return_value=cache_key),
|
||||||
patch("helpers.temp_folder", str(tmp_path)),
|
patch("helpers.temp_folder", str(tmp_path)),
|
||||||
):
|
):
|
||||||
result = helpers.create_components_graph()
|
result = helpers.create_components_graph()
|
||||||
@@ -1246,7 +1246,7 @@ def test_cache_key_mismatch_ignored(tmp_path: Path, mock_git_output: str) -> Non
|
|||||||
|
|
||||||
with (
|
with (
|
||||||
patch("subprocess.run", return_value=mock_result),
|
patch("subprocess.run", return_value=mock_result),
|
||||||
patch("helpers._get_components_graph_cache_key", return_value=new_key),
|
patch("helpers.get_components_graph_cache_key", return_value=new_key),
|
||||||
patch("helpers.temp_folder", str(tmp_path)),
|
patch("helpers.temp_folder", str(tmp_path)),
|
||||||
):
|
):
|
||||||
# Cache key mismatch should cause cache to be ignored
|
# Cache key mismatch should cause cache to be ignored
|
||||||
|
|||||||
Reference in New Issue
Block a user