mirror of
https://github.com/esphome/esphome.git
synced 2025-10-12 14:53:49 +01:00
uart grouping
This commit is contained in:
@@ -24,6 +24,7 @@ Example output:
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from functools import lru_cache
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
@@ -32,25 +33,23 @@ import sys
|
|||||||
# Path to common bus configs
|
# Path to common bus configs
|
||||||
COMMON_BUS_PATH = Path("tests/test_build_components/common")
|
COMMON_BUS_PATH = Path("tests/test_build_components/common")
|
||||||
|
|
||||||
# Valid common bus config directories
|
|
||||||
# All bus types support component grouping for config validation since
|
@lru_cache(maxsize=1)
|
||||||
# --testing-mode bypasses runtime conflicts (we only care that configs compile)
|
def get_common_bus_packages() -> frozenset[str]:
|
||||||
VALID_BUS_CONFIGS = {
|
"""Get the list of common bus package names.
|
||||||
"ble",
|
|
||||||
"i2c",
|
Reads from tests/test_build_components/common/ directory
|
||||||
"i2c_low_freq",
|
and caches the result. All bus types support component grouping
|
||||||
"qspi",
|
for config validation since --testing-mode bypasses runtime conflicts.
|
||||||
"spi",
|
|
||||||
"uart",
|
Returns:
|
||||||
"uart_115200",
|
Frozenset of common bus package names (i2c, spi, uart, etc.)
|
||||||
"uart_1200",
|
"""
|
||||||
"uart_1200_even",
|
if not COMMON_BUS_PATH.exists():
|
||||||
"uart_19200",
|
return frozenset()
|
||||||
"uart_38400",
|
|
||||||
"uart_4800",
|
# List all directories in common/ - these are the bus package names
|
||||||
"uart_4800_even",
|
return frozenset(d.name for d in COMMON_BUS_PATH.iterdir() if d.is_dir())
|
||||||
"uart_9600_even",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def uses_local_file_references(component_dir: Path) -> bool:
|
def uses_local_file_references(component_dir: Path) -> bool:
|
||||||
@@ -97,6 +96,7 @@ def extract_common_buses(yaml_file: Path) -> set[str]:
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
buses = set()
|
buses = set()
|
||||||
|
valid_buses = get_common_bus_packages()
|
||||||
|
|
||||||
# Pattern to match package includes for common bus configs
|
# Pattern to match package includes for common bus configs
|
||||||
# Matches: !include ../../test_build_components/common/{bus}/{platform}.yaml
|
# Matches: !include ../../test_build_components/common/{bus}/{platform}.yaml
|
||||||
@@ -104,7 +104,7 @@ def extract_common_buses(yaml_file: Path) -> set[str]:
|
|||||||
|
|
||||||
for match in re.finditer(pattern, content):
|
for match in re.finditer(pattern, content):
|
||||||
bus_name = match.group(1)
|
bus_name = match.group(1)
|
||||||
if bus_name in VALID_BUS_CONFIGS:
|
if bus_name in valid_buses:
|
||||||
buses.add(bus_name)
|
buses.add(bus_name)
|
||||||
|
|
||||||
return buses
|
return buses
|
||||||
@@ -199,7 +199,8 @@ def create_grouping_signature(
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
# Only include valid bus types in signature
|
# Only include valid bus types in signature
|
||||||
valid_buses = [b for b in buses if b in VALID_BUS_CONFIGS]
|
common_buses = get_common_bus_packages()
|
||||||
|
valid_buses = [b for b in buses if b in common_buses]
|
||||||
if not valid_buses:
|
if not valid_buses:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@@ -16,7 +16,6 @@ The merger handles:
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from functools import lru_cache
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@@ -27,24 +26,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
|||||||
|
|
||||||
from esphome import yaml_util
|
from esphome import yaml_util
|
||||||
from esphome.config_helpers import merge_config
|
from esphome.config_helpers import merge_config
|
||||||
|
from script.analyze_component_buses import get_common_bus_packages
|
||||||
|
|
||||||
@lru_cache(maxsize=1)
|
|
||||||
def get_common_bus_packages() -> frozenset[str]:
|
|
||||||
"""Get the list of common bus package names.
|
|
||||||
|
|
||||||
Reads from tests/test_build_components/common/ directory
|
|
||||||
and caches the result.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Frozenset of common bus package names (i2c, spi, uart, etc.)
|
|
||||||
"""
|
|
||||||
common_dir = Path("tests/test_build_components/common")
|
|
||||||
if not common_dir.exists():
|
|
||||||
return frozenset()
|
|
||||||
|
|
||||||
# List all directories in common/ - these are the bus package names
|
|
||||||
return frozenset(d.name for d in common_dir.iterdir() if d.is_dir())
|
|
||||||
|
|
||||||
|
|
||||||
def load_yaml_file(yaml_file: Path) -> dict:
|
def load_yaml_file(yaml_file: Path) -> dict:
|
||||||
|
Reference in New Issue
Block a user