Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0399682

Browse files
committed
Skip some uses of packaging's PEP440 version for non-Python versions.
Version numbers from non-Python packages don't have to follow PEP440, and there are at least a few cases where we can check for string equality (when we don't need ordering) or rely on the library's own version parsing (qt).
1 parent a3ba7cf commit 0399682

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

lib/matplotlib/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def wrapper(**kwargs):
278278
return wrapper
279279

280280

281-
_ExecInfo = namedtuple("_ExecInfo", "executable version")
281+
_ExecInfo = namedtuple("_ExecInfo", "executable raw_version version")
282282

283283

284284
class ExecutableNotFoundError(FileNotFoundError):
@@ -339,12 +339,13 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
339339
raise ExecutableNotFoundError(str(_ose)) from _ose
340340
match = re.search(regex, output)
341341
if match:
342-
version = parse_version(match.group(1))
342+
raw_version = match.group(1)
343+
version = parse_version(raw_version)
343344
if min_ver is not None and version < parse_version(min_ver):
344345
raise ExecutableNotFoundError(
345346
f"You have {args[0]} version {version} but the minimum "
346347
f"version supported by Matplotlib is {min_ver}")
347-
return _ExecInfo(args[0], version)
348+
return _ExecInfo(args[0], raw_version, version)
348349
else:
349350
raise ExecutableNotFoundError(
350351
f"Failed to determine the version of {args[0]} from "
@@ -401,7 +402,7 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
401402
else:
402403
path = "convert"
403404
info = impl([path, "--version"], r"^Version: ImageMagick (\S*)")
404-
if info.version == parse_version("7.0.10-34"):
405+
if info.raw_version == "7.0.10-34":
405406
# https://github.com/ImageMagick/ImageMagick/issues/2720
406407
raise ExecutableNotFoundError(
407408
f"You have ImageMagick {info.version}, which is unsupported")

lib/matplotlib/backends/qt_compat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ def _isdeleted(obj):
134134
# https://bugreports.qt.io/browse/QTBUG-87014, fixed in qt 5.15.2
135135
if (sys.platform == 'darwin' and
136136
parse_version(platform.mac_ver()[0]) >= parse_version("10.16") and
137-
parse_version(QtCore.qVersion()) < parse_version("5.15.2") and
138-
"QT_MAC_WANTS_LAYER" not in os.environ):
139-
os.environ["QT_MAC_WANTS_LAYER"] = "1"
137+
QtCore.QLibraryInfo.version().segments() <= [5, 15, 2]):
138+
os.environ.setdefault("QT_MAC_WANTS_LAYER", "1")
140139

141140

142141
# PyQt6 enum compat helpers.

lib/matplotlib/texmanager.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from tempfile import TemporaryDirectory
3030

3131
import numpy as np
32-
from packaging.version import parse as parse_version
3332

3433
import matplotlib as mpl
3534
from matplotlib import _api, cbook, dviread, rcParams
@@ -291,9 +290,8 @@ def make_png(self, tex, fontsize, dpi):
291290
# dvipng 1.16 has a bug (fixed in f3ff241) that breaks --freetype0
292291
# mode, so for it we keep FreeType enabled; the image will be
293292
# slightly off.
294-
bad_ver = parse_version("1.16")
295-
if (getattr(mpl, "_called_from_pytest", False)
296-
and mpl._get_executable_info("dvipng").version != bad_ver):
293+
if (getattr(mpl, "_called_from_pytest", False) and
294+
mpl._get_executable_info("dvipng").raw_version != "1.16"):
297295
cmd.insert(1, "--freetype0")
298296
self._run_checked_subprocess(cmd, tex)
299297
return pngfile

0 commit comments

Comments
 (0)