[image] Make PIL import local (#6864)

This commit is contained in:
guillempages 2024-06-12 03:11:00 +02:00 committed by GitHub
parent e2784d077d
commit 699d00e218
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,8 +9,6 @@ import re
import requests import requests
from magic import Magic from magic import Magic
from PIL import Image
from esphome import core from esphome import core
from esphome.components import font from esphome.components import font
from esphome import external_files from esphome import external_files
@ -267,6 +265,9 @@ CONFIG_SCHEMA = cv.All(font.validate_pillow_installed, IMAGE_SCHEMA)
def load_svg_image(file: bytes, resize: tuple[int, int]): def load_svg_image(file: bytes, resize: tuple[int, int]):
# Local import only to allow "validate_pillow_installed" to run *before* importing it
from PIL import Image
# This import is only needed in case of SVG images; adding it # This import is only needed in case of SVG images; adding it
# to the top would force configurations not using SVG to also have it # to the top would force configurations not using SVG to also have it
# installed for no reason. # installed for no reason.
@ -286,6 +287,9 @@ def load_svg_image(file: bytes, resize: tuple[int, int]):
async def to_code(config): async def to_code(config):
# Local import only to allow "validate_pillow_installed" to run *before* importing it
from PIL import Image
conf_file = config[CONF_FILE] conf_file = config[CONF_FILE]
if conf_file[CONF_SOURCE] == SOURCE_LOCAL: if conf_file[CONF_SOURCE] == SOURCE_LOCAL: