Skip to content

Commit 9734024

Browse files
miss-islingtonserhiy-storchaka
authored andcommitted
bpo-26544: Get rid of dependence from distutils in platform. (GH-8356) (GH-8952)
(cherry picked from commit 7d81e8f) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 7056ca8 commit 9734024

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Lib/platform.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@
132132
# Standard Unix uses /dev/null
133133
DEV_NULL = '/dev/null'
134134

135+
# Helper for comparing two version number strings.
136+
# Based on the description of the PHP's version_compare():
137+
# http://php.net/manual/en/function.version-compare.php
138+
139+
_ver_stages = {
140+
# any string not found in this dict, will get 0 assigned
141+
'dev': 10,
142+
'alpha': 20, 'a': 20,
143+
'beta': 30, 'b': 30,
144+
'c': 40,
145+
'RC': 50, 'rc': 50,
146+
# number, will get 100 assigned
147+
'pl': 200, 'p': 200,
148+
}
149+
150+
_component_re = re.compile(r'([0-9]+|[._+-])')
151+
152+
def _comparable_version(version):
153+
result = []
154+
for v in _component_re.split(version):
155+
if v not in '._+-':
156+
try:
157+
v = int(v, 10)
158+
t = 100
159+
except ValueError:
160+
t = _ver_stages.get(v, 0)
161+
result.extend((t, v))
162+
return result
163+
135164
### Platform specific APIs
136165

137166
_libc_search = re.compile(r'(__libc_init)'
@@ -155,7 +184,7 @@ def libc_ver(executable=sys.executable,lib='',version='', chunksize=2048):
155184
The file is read and scanned in chunks of chunksize bytes.
156185
157186
"""
158-
from distutils.version import LooseVersion as V
187+
V = _comparable_version
159188
if hasattr(os.path, 'realpath'):
160189
# Python 2.2 introduced os.path.realpath(); it is used
161190
# here to work around problems with Cygwin not being

0 commit comments

Comments
 (0)