summaryrefslogtreecommitdiffstats
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-08-27 10:29:51 (GMT)
committerGitHub <noreply@github.com>2018-08-27 10:29:51 (GMT)
commit7d81e8f5995df6980a1a02923e224a481375f130 (patch)
treea66f52490ef1850ab24fd9c9c17ffe75398cc4b9 /Lib/platform.py
parentb44a1d4f71daf4edb948b9878f82a60891e4a2e1 (diff)
downloadcpython-7d81e8f5995df6980a1a02923e224a481375f130.zip
cpython-7d81e8f5995df6980a1a02923e224a481375f130.tar.gz
cpython-7d81e8f5995df6980a1a02923e224a481375f130.tar.bz2
bpo-26544: Get rid of dependence from distutils in platform. (GH-8356)
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-xLib/platform.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/platform.py b/Lib/platform.py
index a7785a2..f7e24d7 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -132,6 +132,35 @@ except AttributeError:
# 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, will get 0 assigned
+ 'dev': 10,
+ 'alpha': 20, 'a': 20,
+ 'beta': 30, 'b': 30,
+ 'c': 40,
+ 'RC': 50, 'rc': 50,
+ # number, will get 100 assigned
+ '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.extend((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