mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 12:38:40 +00:00
[core] Defer requests import in framework_helpers
framework_helpers imported requests at module top level, but it is only used by download_from_mirrors() to fetch toolchains during a build. The module is loaded during config validation (via the esp-idf framework, the default for esp32, and the host platform), so every such config paid the ~85ms requests import cost even though validation never downloads anything. Defer the import into download_from_mirrors(). Measured roughly 70ms (~16%) off esphome config wall time for an esp-idf/host config.
This commit is contained in:
@@ -11,8 +11,6 @@ import sys
|
||||
import time
|
||||
from typing import IO
|
||||
|
||||
import requests
|
||||
|
||||
from esphome.helpers import ProgressBar, rmtree
|
||||
|
||||
PathType = str | os.PathLike
|
||||
@@ -635,6 +633,10 @@ def download_from_mirrors(
|
||||
ValueError: If mirrors list is empty.
|
||||
Exception: If all download attempts fail.
|
||||
"""
|
||||
# Imported lazily: requests is a heavy import (~85ms) and is only needed
|
||||
# when actually downloading a toolchain, never during config validation.
|
||||
import requests
|
||||
|
||||
# 1. Open target file for writing if path given
|
||||
with ExitStack() as stack:
|
||||
if isinstance(target, (str, os.PathLike)):
|
||||
|
||||
Reference in New Issue
Block a user