From 043d8dac0b5259d73036f8f49aecfafc439f6244 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 18 Dec 2020 23:42:16 +1100 Subject: [PATCH] Do not require packaging just for a DeprecationWarning --- src/PIL/ImageFont.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 78f8d8cde..c48d89835 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -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