Do not require packaging just for a DeprecationWarning

This commit is contained in:
Andrew Murray 2020-12-18 23:42:16 +11:00
parent cfc45ab9c3
commit 043d8dac0b

View File

@ -31,8 +31,6 @@ import sys
import warnings
from io import BytesIO
from packaging.version import parse as parse_version
from . import Image, features
from ._util import isDirectory, isPath
@ -167,14 +165,20 @@ class FreeTypeFont:
self.index = index
self.encoding = encoding
freetype_version = parse_version(features.version_module("freetype2"))
if freetype_version < parse_version("2.8"):
warnings.warn(
"Support for FreeType 2.7 is deprecated and will be removed in Pillow "
"9 (2022-01-02). Please upgrade to FreeType 2.8 or newer, preferably "
"FreeType 2.10.4 which fixes CVE-2020-15999.",
DeprecationWarning,
)
try:
from packaging.version import parse as parse_version
except ImportError:
pass
else:
freetype_version = parse_version(features.version_module("freetype2"))
if freetype_version < parse_version("2.8"):
warnings.warn(
"Support for FreeType 2.7 is deprecated and will be removed"
" in Pillow 9 (2022-01-02). Please upgrade to FreeType 2.8 "
"or newer, preferably FreeType 2.10.4 which fixes "
"CVE-2020-15999.",
DeprecationWarning,
)
if layout_engine not in (LAYOUT_BASIC, LAYOUT_RAQM):
layout_engine = LAYOUT_BASIC