Issue #25985: sys.version_info is now used instead of sys.version · python/cpython@885bdc4 · GitHub
Skip to content

Commit 885bdc4

Browse files
Issue #25985: sys.version_info is now used instead of sys.version
to format short Python version.
1 parent a9725f8 commit 885bdc4

24 files changed

Lines changed: 56 additions & 52 deletions

Doc/c-api/intro.rst

Lines changed: 4 additions & 3 deletions

Doc/includes/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
import os
205205
import sys
206206
from distutils.util import get_platform
207-
PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
207+
PLAT_SPEC = "%s-%d.%d" % (get_platform(), *sys.version_info[:2])
208208
src = os.path.join("build", "lib.%s" % PLAT_SPEC)
209209
sys.path.append(src)
210210

Doc/library/sysconfig.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Other functions
163163
.. function:: get_python_version()
164164

165165
Return the ``MAJOR.MINOR`` Python version number as a string. Similar to
166-
``sys.version[:3]``.
166+
``'%d.%d' % sys.version_info[:2]``.
167167

168168

169169
.. function:: get_platform()

Lib/distutils/command/bdist_msi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def run(self):
199199
target_version = self.target_version
200200
if not target_version:
201201
assert self.skip_build, "Should have already checked this"
202-
target_version = sys.version[0:3]
202+
target_version = '%d.%d' % sys.version_info[:2]
203203
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
204204
build = self.get_finalized_command('build')
205205
build.build_lib = os.path.join(build.build_base,

Lib/distutils/command/bdist_wininst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def run(self):
141141
target_version = self.target_version
142142
if not target_version:
143143
assert self.skip_build, "Should have already checked this"
144-
target_version = sys.version[0:3]
144+
target_version = '%d.%d' % sys.version_info[:2]
145145
plat_specifier = ".%s-%s" % (self.plat_name, target_version)
146146
build = self.get_finalized_command('build')
147147
build.build_lib = os.path.join(build.build_base,

Lib/distutils/command/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def finalize_options(self):
8181
"--plat-name only supported on Windows (try "
8282
"using './configure --help' on your platform)")
8383

84-
plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
84+
plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
8585

8686
# Make it so Python 2.x and Python 2.x with --with-pydebug don't
8787
# share the same build directories. Doing so confuses the build
@@ -114,7 +114,7 @@ def finalize_options(self):
114114
'temp' + plat_specifier)
115115
if self.build_scripts is None:
116116
self.build_scripts = os.path.join(self.build_base,
117-
'scripts-' + sys.version[0:3])
117+
'scripts-%d.%d' % sys.version_info[:2])
118118

119119
if self.executable is None:
120120
self.executable = os.path.normpath(sys.executable)

Lib/distutils/command/install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ def finalize_options(self):
290290
'dist_version': self.distribution.get_version(),
291291
'dist_fullname': self.distribution.get_fullname(),
292292
'py_version': py_version,
293-
'py_version_short': py_version[0:3],
294-
'py_version_nodot': py_version[0] + py_version[2],
293+
'py_version_short': '%d.%d' % sys.version_info[:2],
294+
'py_version_nodot': '%d%d' % sys.version_info[:2],
295295
'sys_prefix': prefix,
296296
'prefix': prefix,
297297
'sys_exec_prefix': exec_prefix,

Lib/distutils/command/install_egg_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def initialize_options(self):
2121

2222
def finalize_options(self):
2323
self.set_undefined_options('install_lib',('install_dir','install_dir'))
24-
basename = "%s-%s-py%s.egg-info" % (
24+
basename = "%s-%s-py%d.%d.egg-info" % (
2525
to_filename(safe_name(self.distribution.get_name())),
2626
to_filename(safe_version(self.distribution.get_version())),
27-
sys.version[:3]
27+
*sys.version_info[:2]
2828
)
2929
self.target = os.path.join(self.install_dir, basename)
3030
self.outputs = [self.target]

Lib/distutils/sysconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def get_python_version():
7070
leaving off the patchlevel. Sample return values could be '1.5'
7171
or '2.2'.
7272
"""
73-
return sys.version[:3]
73+
return '%d.%d' % sys.version_info[:2]
7474

7575

7676
def get_python_inc(plat_specific=0, prefix=None):

Lib/distutils/tests/test_build.py

Lines changed: 3 additions & 2 deletions

0 commit comments

Comments
 (0)