From b2e626d4849a0f266b6c6eec8d9e1038db47badf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 27 Aug 2026 19:21:15 -0500 Subject: [PATCH] Run the sequential remainder after the batch --- esphome/platformio/registry.py | 11 ++++++----- tests/unit_tests/test_platformio_registry.py | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/esphome/platformio/registry.py b/esphome/platformio/registry.py index dc1f4441c5..e6092e8b9c 100644 --- a/esphome/platformio/registry.py +++ b/esphome/platformio/registry.py @@ -389,11 +389,8 @@ def install_packages(specs: Collection[PackageSpec], downloads_dir: Path) -> Non seen.add(archive.name) pending.append((spec, size)) if len(pending) < 2: - rest = list(specs) - pending = [] - for name, version, dest, mirrors, expect in rest: - install_package(name, version, dest, mirrors, downloads_dir, expect=expect) - if not pending: + for name, version, dest, mirrors, expect in specs: + install_package(name, version, dest, mirrors, downloads_dir, expect=expect) return workers = min(get_usable_cpu_count(), len(pending), BATCH_EXTRACT_WORKERS) _LOGGER.info( @@ -425,3 +422,7 @@ def install_packages(specs: Collection[PackageSpec], downloads_dir: Path) -> Non # not name which package failed warn_batch_failures(failures, "Could not install %s: %s") raise failures[0][1] + # Sequential remainder after the batch, so a duplicate spec cannot + # unlink the archive its batched twin was sized from + for name, version, dest, mirrors, expect in rest: + install_package(name, version, dest, mirrors, downloads_dir, expect=expect) diff --git a/tests/unit_tests/test_platformio_registry.py b/tests/unit_tests/test_platformio_registry.py index e5023ca3f4..be7d31c0b7 100644 --- a/tests/unit_tests/test_platformio_registry.py +++ b/tests/unit_tests/test_platformio_registry.py @@ -906,6 +906,8 @@ def test_install_packages_dedupes_duplicate_specs(tmp_path: Path) -> None: batched = [c for c in mock_install.call_args_list if "extract_progress" in c[1]] assert [(c[0][0], c[0][2]) for c in sequential] == [("a", tmp_path / "a2")] assert sorted(c[0][0] for c in batched) == ["a", "b"] + # The duplicate runs after the batch, which unlinks their shared archive + assert mock_install.call_args_list[-1] == sequential[0] def test_install_packages_caps_workers(tmp_path: Path) -> None: