diff options
author | Dominic Davis-Foster <dominic@davis-foster.co.uk> | 2021-04-12 18:39:01 +0100 |
---|---|---|
committer | Dominic Davis-Foster <dominic@davis-foster.co.uk> | 2021-04-12 19:24:01 +0100 |
commit | c9acbba07c28b987071780f291c42e89634f1862 (patch) | |
tree | 3a63beba452647bb28753f5a4eb68a20414a5a6d /natsort | |
parent | 4e47f82856822ac776b4874747852b99edb79d9e (diff) | |
download | natsort-c9acbba07c28b987071780f291c42e89634f1862.tar.gz |
Don't import distutils to check the fastnumbers version.
Blacken
Diffstat (limited to 'natsort')
-rw-r--r-- | natsort/compat/fastnumbers.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/natsort/compat/fastnumbers.py b/natsort/compat/fastnumbers.py index b6b0bb1..4f4d75a 100644 --- a/natsort/compat/fastnumbers.py +++ b/natsort/compat/fastnumbers.py @@ -4,7 +4,25 @@ Interface for natsort to access fastnumbers functions without having to worry if it is actually installed. """ -from distutils.version import StrictVersion +import re + + +def is_supported_fastnumbers(fastnumbers_version: str) -> bool: + match = re.match( + r"^(\d+)\.(\d+)(\.(\d+))?([ab](\d+))?$", + fastnumbers_version, + flags=re.ASCII, + ) + + if not match: + raise ValueError( + "Invalid fastnumbers version number '{}'".format(fastnumbers_version) + ) + + (major, minor, patch) = match.group(1, 2, 4) + + return (int(major), int(minor), int(patch)) >= (2, 0, 0) + # If the user has fastnumbers installed, they will get great speed # benefits. If not, we use the simulated functions that come with natsort. @@ -13,7 +31,7 @@ try: from fastnumbers import fast_float, fast_int, __version__ as fn_ver # Require >= version 2.0.0. - if StrictVersion(fn_ver) < StrictVersion("2.0.0"): + if not is_supported_fastnumbers(fn_ver): raise ImportError # pragma: no cover except ImportError: from natsort.compat.fake_fastnumbers import fast_float, fast_int # noqa: F401 |