Use importlib.metadata.entry_points to load PIL.Image.decoder entries on init()

This commit is contained in:
Mattijs Ugen 2022-02-18 14:11:05 +01:00
parent 6b8edca6df
commit dd030343b8

View File

@ -44,6 +44,12 @@ try:
except ImportError:
ElementTree = None
try:
from importlib.metadata import entry_points
except ImportError:
# NB: potentially try to load entry_points from backported importlib_metadata?
entry_points = None
# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0.
# Use __version__ instead.
@ -374,6 +380,12 @@ def init():
except ImportError as e:
logger.debug("Image: failed to import %s: %s", plugin, e)
if entry_points:
for decoder in entry_points(group='PIL.Image.decoder'):
# or, alternatively, register a decoder directly from here:
# DECODERS[decoder.name] = decoder.load()
decoder.load()
if OPEN or SAVE:
_initialized = 2
return 1