From b68750a9d0dc0bdf51aae7ce3bd7151027820086 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 20 Jul 2018 20:39:48 +0300 Subject: [PATCH 1/2] bpo-26544: Get rid of dependence from distutils in platform. --- Lib/platform.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Lib/platform.py b/Lib/platform.py index a7785a22440ed25..d44e461cdedf0c7 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -132,6 +132,35 @@ # Standard Unix uses /dev/null DEV_NULL = '/dev/null' +# Helper for comparing two version number strings +# Based on the description of the PHP's version_compare(): +# http://php.net/manual/en/function.version-compare.php + +_ver_stages = { + # any string not found in this dict + 'dev': 10, + 'alpha': 20, 'a': 20, + 'beta': 30, 'b': 30, + 'c': 40, + 'RC': 50, 'rc': 50, + # number + 'pl': 200, 'p': 200, +} + +_component_re = re.compile(r'([0-9]+|[._+-])') + +def _comparable_version(version): + result = [] + for v in _component_re.split(version): + if v not in '._+-': + try: + v = int(v, 10) + t = 100 + except ValueError: + t = _ver_stages.get(v, 0) + result.append((t, v)) + return result + ### Platform specific APIs _libc_search = re.compile(b'(__libc_init)' @@ -155,7 +184,7 @@ def libc_ver(executable=sys.executable, lib='', version='', chunksize=16384): The file is read and scanned in chunks of chunksize bytes. """ - from distutils.version import LooseVersion as V + V = _comparable_version if hasattr(os.path, 'realpath'): # Python 2.2 introduced os.path.realpath(); it is used # here to work around problems with Cygwin not being From d8b60ba1ef42981eb7744d279490308ef17088d2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 25 Aug 2018 10:25:00 +0300 Subject: [PATCH 2/2] Update comments. --- Lib/platform.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/platform.py b/Lib/platform.py index d44e461cdedf0c7..f7e24d739c6d352 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -132,18 +132,18 @@ # Standard Unix uses /dev/null DEV_NULL = '/dev/null' -# Helper for comparing two version number strings +# Helper for comparing two version number strings. # Based on the description of the PHP's version_compare(): # http://php.net/manual/en/function.version-compare.php _ver_stages = { - # any string not found in this dict + # any string not found in this dict, will get 0 assigned 'dev': 10, 'alpha': 20, 'a': 20, 'beta': 30, 'b': 30, 'c': 40, 'RC': 50, 'rc': 50, - # number + # number, will get 100 assigned 'pl': 200, 'p': 200, } @@ -158,7 +158,7 @@ def _comparable_version(version): t = 100 except ValueError: t = _ver_stages.get(v, 0) - result.append((t, v)) + result.extend((t, v)) return result ### Platform specific APIs