Thanks to visit codestin.com
Credit goes to github.com

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
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ The header files are typically installed with Python. On Unix, these are
6464
located in the directories :file:`{prefix}/include/pythonversion/` and
6565
:file:`{exec_prefix}/include/pythonversion/`, where :envvar:`prefix` and
6666
:envvar:`exec_prefix` are defined by the corresponding parameters to Python's
67-
:program:`configure` script and *version* is ``sys.version[:3]``. On Windows,
68-
the headers are installed in :file:`{prefix}/include`, where :envvar:`prefix` is
69-
the installation directory specified to the installer.
67+
:program:`configure` script and *version* is
68+
``'%d.%d' % sys.version_info[:2]``. On Windows, the headers are installed
69+
in :file:`{prefix}/include`, where :envvar:`prefix` is the installation
70+
directory specified to the installer.
7071

7172
To include the headers, place both directories (if different) on your compiler's
7273
search path for includes. Do *not* place the parent directories on the search

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
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_finalize_options(self):
2727
# build_platlib is 'build/lib.platform-x.x[-pydebug]'
2828
# examples:
2929
# build/lib.macosx-10.3-i386-2.7
30-
plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
30+
plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
3131
if hasattr(sys, 'gettotalrefcount'):
3232
self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
3333
plat_spec += '-pydebug'
@@ -42,7 +42,8 @@ def test_finalize_options(self):
4242
self.assertEqual(cmd.build_temp, wanted)
4343

4444
# build_scripts is build/scripts-x.x
45-
wanted = os.path.join(cmd.build_base, 'scripts-' + sys.version[0:3])
45+
wanted = os.path.join(cmd.build_base,
46+
'scripts-%d.%d' % sys.version_info[:2])
4647
self.assertEqual(cmd.build_scripts, wanted)
4748

4849
# executable is os.path.normpath(sys.executable)

0 commit comments

Comments
 (0)