[image] Make PIL import local (#6864)

This commit is contained in:
guillempages authored and GitHub committed 2024-06-12 13:11:00 +12:00
1 parent e2784d077d
commit 699d00e218
1 file changed
+6 -2
+6 -2
View File
@@ -9,8 +9,6 @@ import re
import requests
from magic import Magic
from PIL import Image
from esphome import core
from esphome.components import font
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]):
# 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
# to the top would force configurations not using SVG to also have it
# installed for no reason.
@@ -286,6 +287,9 @@ def load_svg_image(file: bytes, resize: tuple[int, int]):
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]
if conf_file[CONF_SOURCE] == SOURCE_LOCAL: