mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
[core] Import yaml_util once per build in generate_cpp_contents
Address copilot review: wrap_to_code is called once per component, so the lazy `from esphome import yaml_util` inside it was doing a (cached) sys.modules lookup per component. Move the import up to generate_cpp_contents, pass the module down, rename the helper to _wrap_to_code to mark it private.
This commit is contained in:
+4
-4
@@ -667,9 +667,7 @@ def run_miniterm(config: ConfigType, port: str, args) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def wrap_to_code(name, comp):
|
||||
from esphome import yaml_util
|
||||
|
||||
def _wrap_to_code(name, comp, yaml_util):
|
||||
coro = coroutine(comp.to_code)
|
||||
|
||||
@functools.wraps(comp.to_code)
|
||||
@@ -702,11 +700,13 @@ def write_cpp(config: ConfigType, native_idf: bool = False) -> int:
|
||||
|
||||
|
||||
def generate_cpp_contents(config: ConfigType) -> None:
|
||||
from esphome import yaml_util
|
||||
|
||||
_LOGGER.info("Generating C++ source...")
|
||||
|
||||
for name, component, conf in iter_component_configs(CORE.config):
|
||||
if component.to_code is not None:
|
||||
coro = wrap_to_code(name, component)
|
||||
coro = _wrap_to_code(name, component, yaml_util)
|
||||
CORE.add_job(coro, conf)
|
||||
|
||||
CORE.flush_tasks()
|
||||
|
||||
Reference in New Issue
Block a user