From abbd72e8028d8fdfdd5caf3fd46023d19ce0dea4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Feb 2025 11:10:33 -0600 Subject: [PATCH 1/4] Use the process CPU count to determine how many children to create (#8268) --- esphome/core/config.py | 16 ++++++++++++---- script/clang-format | 22 +++++++++++++++------- script/clang-tidy | 4 ++-- script/helpers.py | 11 +++++++++++ 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/esphome/core/config.py b/esphome/core/config.py index 2077af02a7..359b78acf1 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -1,5 +1,4 @@ import logging -import multiprocessing import os from pathlib import Path @@ -94,10 +93,19 @@ def valid_project_name(value: str): return value +def get_usable_cpu_count() -> int: + """Return the number of CPUs that can be used for processes. + On Python 3.13+ this is the number of CPUs that can be used for processes. + On older Python versions this is the number of CPUs. + """ + return ( + os.process_cpu_count() if hasattr(os, "process_cpu_count") else os.cpu_count() + ) + + if "ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT" in os.environ: _compile_process_limit_default = min( - int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]), - multiprocessing.cpu_count(), + int(os.environ["ESPHOME_DEFAULT_COMPILE_PROCESS_LIMIT"]), get_usable_cpu_count() ) else: _compile_process_limit_default = cv.UNDEFINED @@ -156,7 +164,7 @@ CONFIG_SCHEMA = cv.All( ), cv.Optional( CONF_COMPILE_PROCESS_LIMIT, default=_compile_process_limit_default - ): cv.int_range(min=1, max=multiprocessing.cpu_count()), + ): cv.int_range(min=1, max=get_usable_cpu_count()), } ), validate_hostname, diff --git a/script/clang-format b/script/clang-format index d922c5b6f1..b1e84a56b7 100755 --- a/script/clang-format +++ b/script/clang-format @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import argparse -import multiprocessing import os import queue import re @@ -11,7 +10,13 @@ import threading import click import colorama -from helpers import filter_changed, get_binary, git_ls_files, print_error_for_file +from helpers import ( + filter_changed, + get_binary, + get_usable_cpu_count, + git_ls_files, + print_error_for_file, +) def run_format(executable, args, queue, lock, failed_files): @@ -25,7 +30,9 @@ def run_format(executable, args, queue, lock, failed_files): invocation.extend(["--dry-run", "-Werror"]) invocation.append(path) - proc = subprocess.run(invocation, capture_output=True, encoding="utf-8") + proc = subprocess.run( + invocation, capture_output=True, encoding="utf-8", check=False + ) if proc.returncode != 0: with lock: print_error_for_file(path, proc.stderr) @@ -45,7 +52,7 @@ def main(): "-j", "--jobs", type=int, - default=multiprocessing.cpu_count(), + default=get_usable_cpu_count(), help="number of format instances to be run in parallel.", ) parser.add_argument( @@ -80,7 +87,8 @@ def main(): lock = threading.Lock() for _ in range(args.jobs): t = threading.Thread( - target=run_format, args=(executable, args, task_queue, lock, failed_files) + target=run_format, + args=(executable, args, task_queue, lock, failed_files), ) t.daemon = True t.start() @@ -95,7 +103,7 @@ def main(): # Wait for all threads to be done. task_queue.join() - except FileNotFoundError as ex: + except FileNotFoundError: return 1 except KeyboardInterrupt: print() @@ -103,7 +111,7 @@ def main(): # Kill subprocesses (and ourselves!) # No simple, clean alternative appears to be available. os.kill(0, 9) - return 2 # Will not execute. + return 2 # Will not execute. return len(failed_files) diff --git a/script/clang-tidy b/script/clang-tidy index 5c19f81043..51705f955b 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import argparse -import multiprocessing import os import queue import re @@ -19,6 +18,7 @@ from helpers import ( filter_changed, filter_grep, get_binary, + get_usable_cpu_count, git_ls_files, load_idedata, print_error_for_file, @@ -170,7 +170,7 @@ def main(): "-j", "--jobs", type=int, - default=multiprocessing.cpu_count(), + default=get_usable_cpu_count(), help="number of tidy instances to be run in parallel.", ) parser.add_argument( diff --git a/script/helpers.py b/script/helpers.py index 6f36faaeb1..6148371e32 100644 --- a/script/helpers.py +++ b/script/helpers.py @@ -188,3 +188,14 @@ def get_binary(name: str, version: str) -> str: """ ) raise + + +def get_usable_cpu_count() -> int: + """Return the number of CPUs that can be used for processes. + + On Python 3.13+ this is the number of CPUs that can be used for processes. + On older Python versions this is the number of CPUs. + """ + return ( + os.process_cpu_count() if hasattr(os, "process_cpu_count") else os.cpu_count() + ) From 56034e3e79331e9b38db5f4a733486929da753c3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Feb 2025 11:11:58 -0600 Subject: [PATCH 2/4] Bump openssh-client to 1:9.2p1-2+deb12u4 to fix docker builds (#8269) --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1db1ee7b51..6da5c52d64 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -35,7 +35,7 @@ RUN \ iputils-ping=3:20221126-1+deb12u1 \ git=1:2.39.5-0+deb12u1 \ curl=7.88.1-10+deb12u8 \ - openssh-client=1:9.2p1-2+deb12u3 \ + openssh-client=1:9.2p1-2+deb12u4 \ python3-cffi=1.15.1-5 \ libcairo2=1.16.0-7 \ libmagic1=1:5.44-3 \ From b3db04a3d300838c1a3154eed77dc6220d5655eb Mon Sep 17 00:00:00 2001 From: G-Two <7310260+G-Two@users.noreply.github.com> Date: Tue, 18 Feb 2025 12:30:03 -0500 Subject: [PATCH 3/4] Increase default repeat delay for Toto remote transmitter protocol (#8265) --- esphome/components/remote_base/toto_protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/remote_base/toto_protocol.h b/esphome/components/remote_base/toto_protocol.h index e62714bbbf..6a635b0f7c 100644 --- a/esphome/components/remote_base/toto_protocol.h +++ b/esphome/components/remote_base/toto_protocol.h @@ -36,7 +36,7 @@ template class TotoAction : public RemoteTransmitterActionBaserc_code_2_.value(x...); data.command = this->command_.value(x...); this->set_send_times(this->send_times_.value_or(x..., 3)); - this->set_send_wait(this->send_wait_.value_or(x..., 32000)); + this->set_send_wait(this->send_wait_.value_or(x..., 36000)); TotoProtocol().encode(dst, data); } }; From 02bf33c54887103ec957a78245d5a41f66151212 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 18 Feb 2025 11:38:41 -0600 Subject: [PATCH 4/4] Bump zeroconf to 0.145.1 (#8267) --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c15dcbbbf7..1de6e3dd06 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ esptool==4.7.0 click==8.1.7 esphome-dashboard==20250212.0 aioesphomeapi==29.1.0 -zeroconf==0.144.3 +zeroconf==0.145.1 puremagic==1.27 ruamel.yaml==0.18.6 # dashboard_import esphome-glyphsets==0.1.0