From 81e1774b18595c6bad770c3ea98df90ce99e7260 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 23 Aug 2026 13:12:41 -0500 Subject: [PATCH] Adapt the package prefetch to the folded batch-download API --- esphome/platformio/registry.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/esphome/platformio/registry.py b/esphome/platformio/registry.py index c4b79f5c8e..a473b7f800 100644 --- a/esphome/platformio/registry.py +++ b/esphome/platformio/registry.py @@ -4,6 +4,7 @@ platformio package (identical bits, esphome's own download machinery).""" from __future__ import annotations from collections.abc import Collection +from functools import partial import io import json import logging @@ -13,7 +14,6 @@ import platform from esphome.core import EsphomeError from esphome.framework_helpers import ( - BatchDownloadProgress, archive_extract_all, download_from_mirrors, download_with_resume, @@ -188,27 +188,21 @@ def prefetch_packages( ", ".join(name for name, *_ in pending), ) - def _fetch(entry: tuple[str, str, Path, str, str, int]): + def _fetch(entry: tuple[str, str, Path, str, str, int], tracker) -> None: name, version, dest, url, sha256, size = entry - - def fetch(tracker): - dest.parent.mkdir(parents=True, exist_ok=True) - with FileLock(f"{dest}.lock", fallback_to_soft=False): - download_with_resume( - url, - downloads_dir / f"{name}-{version}", - sha256=sha256, - size=size, - progress=tracker, - ) - - return fetch + dest.parent.mkdir(parents=True, exist_ok=True) + with FileLock(f"{dest}.lock", fallback_to_soft=False): + download_with_resume( + url, + downloads_dir / f"{name}-{version}", + sha256=sha256, + size=size, + progress=tracker, + ) failures = run_batch_downloads( - BatchDownloadProgress( - "Downloading packages", sum(size for *_, size in pending) - ), - [(entry[0], _fetch(entry)) for entry in pending], + "Downloading packages", + [(entry[0], entry[5], partial(_fetch, entry)) for entry in pending], ) for name, err in failures: if isinstance(err, (EsphomeError, OSError)):