diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-05 14:45:57 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2018-09-05 14:45:57 (GMT) |
commit | 1a3eb125dc07a28a5af62446778ed7cca95ed3da (patch) | |
tree | 7e120c35199bc867accf980ac2f1a3473e6d8311 /Lib/platform.py | |
parent | e2c1657dff86decf1e232b66e766d2e51381109c (diff) | |
download | cpython-1a3eb125dc07a28a5af62446778ed7cca95ed3da.zip cpython-1a3eb125dc07a28a5af62446778ed7cca95ed3da.tar.gz cpython-1a3eb125dc07a28a5af62446778ed7cca95ed3da.tar.bz2 |
[3.7] bpo-26544: Get rid of dependence from distutils in platform. (GH-8356) (GH-8970) (GH-9061)
(cherry picked from commit 7d81e8f5995df6980a1a02923e224a481375f130)
(cherry picked from commit 20a8392cec2967f15ae81633c1775645b3ca40da)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-x | Lib/platform.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index c8e0476..4205abd 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -136,6 +136,35 @@ except AttributeError: # Constant used by test_platform to test linux_distribution(). _UNIXCONFDIR = '/etc' +# 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)' @@ -159,7 +188,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 |