|
85 | 85 | from collections import namedtuple
|
86 | 86 | from collections.abc import MutableMapping
|
87 | 87 | import contextlib
|
88 |
| -from distutils.version import LooseVersion |
89 | 88 | import functools
|
90 | 89 | import importlib
|
91 | 90 | import inspect
|
|
103 | 102 | import warnings
|
104 | 103 |
|
105 | 104 | import numpy
|
| 105 | +from packaging.version import parse as parse_version |
106 | 106 |
|
107 | 107 | # cbook must import matplotlib only within function
|
108 | 108 | # definitions, so it is safe to import from it here.
|
@@ -165,9 +165,9 @@ def _check_versions():
|
165 | 165 | ("pyparsing", "2.2.1"),
|
166 | 166 | ]:
|
167 | 167 | module = importlib.import_module(modname)
|
168 |
| - if LooseVersion(module.__version__) < minver: |
169 |
| - raise ImportError("Matplotlib requires {}>={}; you have {}" |
170 |
| - .format(modname, minver, module.__version__)) |
| 168 | + if parse_version(module.__version__) < parse_version(minver): |
| 169 | + raise ImportError(f"Matplotlib requires {modname}>={minver}; " |
| 170 | + f"you have {module.__version__}") |
171 | 171 |
|
172 | 172 |
|
173 | 173 | _check_versions()
|
@@ -274,8 +274,7 @@ def _get_executable_info(name):
|
274 | 274 | -------
|
275 | 275 | tuple
|
276 | 276 | A namedtuple with fields ``executable`` (`str`) and ``version``
|
277 |
| - (`distutils.version.LooseVersion`, or ``None`` if the version cannot be |
278 |
| - determined). |
| 277 | + (`packaging.Version`, or ``None`` if the version cannot be determined). |
279 | 278 |
|
280 | 279 | Raises
|
281 | 280 | ------
|
@@ -305,8 +304,8 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
|
305 | 304 | raise ExecutableNotFoundError(str(_ose)) from _ose
|
306 | 305 | match = re.search(regex, output)
|
307 | 306 | if match:
|
308 |
| - version = LooseVersion(match.group(1)) |
309 |
| - if min_ver is not None and version < min_ver: |
| 307 | + version = parse_version(match.group(1)) |
| 308 | + if min_ver is not None and version < parse_version(min_ver): |
310 | 309 | raise ExecutableNotFoundError(
|
311 | 310 | f"You have {args[0]} version {version} but the minimum "
|
312 | 311 | f"version supported by Matplotlib is {min_ver}")
|
@@ -367,17 +366,18 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
|
367 | 366 | else:
|
368 | 367 | path = "convert"
|
369 | 368 | info = impl([path, "--version"], r"^Version: ImageMagick (\S*)")
|
370 |
| - if info.version == "7.0.10-34": |
| 369 | + if info.version == parse_version("7.0.10-34"): |
371 | 370 | # https://github.com/ImageMagick/ImageMagick/issues/2720
|
372 | 371 | raise ExecutableNotFoundError(
|
373 | 372 | f"You have ImageMagick {info.version}, which is unsupported")
|
374 | 373 | return info
|
375 | 374 | elif name == "pdftops":
|
376 | 375 | info = impl(["pdftops", "-v"], "^pdftops version (.*)",
|
377 | 376 | ignore_exit_code=True)
|
378 |
| - if info and not ("3.0" <= info.version |
379 |
| - # poppler version numbers. |
380 |
| - or "0.9" <= info.version <= "1.0"): |
| 377 | + if info and not ( |
| 378 | + 3 <= info.version.major or |
| 379 | + # poppler version numbers. |
| 380 | + parse_version("0.9") <= info.version < parse_version("1.0")): |
381 | 381 | raise ExecutableNotFoundError(
|
382 | 382 | f"You have pdftops version {info.version} but the minimum "
|
383 | 383 | f"version supported by Matplotlib is 3.0")
|
|
0 commit comments