]> granicus.if.org Git - python/commitdiff
Issue #25985: sys.version_info is now used instead of sys.version
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Feb 2016 11:10:36 +0000 (13:10 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Feb 2016 11:10:36 +0000 (13:10 +0200)
to format short Python version.

24 files changed:
Doc/c-api/intro.rst
Doc/includes/test.py
Doc/library/sysconfig.rst
Lib/distutils/command/bdist_msi.py
Lib/distutils/command/bdist_wininst.py
Lib/distutils/command/build.py
Lib/distutils/command/install.py
Lib/distutils/command/install_egg_info.py
Lib/distutils/sysconfig.py
Lib/distutils/tests/test_build.py
Lib/importlib/_bootstrap_external.py
Lib/pydoc.py
Lib/site.py
Lib/sysconfig.py
Lib/test/test_importlib/test_windows.py
Lib/test/test_site.py
Lib/test/test_venv.py
Lib/urllib/request.py
Lib/xmlrpc/client.py
Makefile.pre.in
Python/importlib_external.h
Tools/freeze/freeze.py
Tools/scripts/nm2def.py
setup.py

index 95cbef567fb30981f57fb75aaed5f240bfca7ec3..74681d2c8518892dd13324281d82e1e82b59b9e7 100644 (file)
@@ -64,9 +64,10 @@ The header files are typically installed with Python.  On Unix, these  are
 located in the directories :file:`{prefix}/include/pythonversion/` and
 :file:`{exec_prefix}/include/pythonversion/`, where :envvar:`prefix` and
 :envvar:`exec_prefix` are defined by the corresponding parameters to Python's
-:program:`configure` script and *version* is ``sys.version[:3]``.  On Windows,
-the headers are installed in :file:`{prefix}/include`, where :envvar:`prefix` is
-the installation directory specified to the installer.
+:program:`configure` script and *version* is
+``'%d.%d' % sys.version_info[:2]``.  On Windows, the headers are installed
+in :file:`{prefix}/include`, where :envvar:`prefix` is the installation
+directory specified to the installer.
 
 To include the headers, place both directories (if different) on your compiler's
 search path for includes.  Do *not* place the parent directories on the search
index 7ebf46afd1ee3c3ed793024cf961c90428229d55..9e9d4a67121cae17d63b86226e4da30f3f1cd002 100644 (file)
@@ -204,7 +204,7 @@ Test cyclic gc(?)
 import os
 import sys
 from distutils.util import get_platform
-PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
+PLAT_SPEC = "%s-%d.%d" % (get_platform(), *sys.version_info[:2])
 src = os.path.join("build", "lib.%s" % PLAT_SPEC)
 sys.path.append(src)
 
index 535ac54b3c02cfd24e51febaf353316aee2b6b05..47f3900eeb79a59b0de23f2ea60e50207c8c9697 100644 (file)
@@ -163,7 +163,7 @@ Other functions
 .. function:: get_python_version()
 
    Return the ``MAJOR.MINOR`` Python version number as a string.  Similar to
-   ``sys.version[:3]``.
+   ``'%d.%d' % sys.version_info[:2]``.
 
 
 .. function:: get_platform()
index b3cfe9ceff7640cf80684ce63e11bc15ab76e848..f6c21aee44084e8314cbfd652bcfdcd7f45a2ded 100644 (file)
@@ -199,7 +199,7 @@ class bdist_msi(Command):
             target_version = self.target_version
             if not target_version:
                 assert self.skip_build, "Should have already checked this"
-                target_version = sys.version[0:3]
+                target_version = '%d.%d' % sys.version_info[:2]
             plat_specifier = ".%s-%s" % (self.plat_name, target_version)
             build = self.get_finalized_command('build')
             build.build_lib = os.path.join(build.build_base,
index 0c0e2c1a26491c6fa360b77edc3ed3177bdac9c8..d3e1d3af22c051420bcf9dff81349b662cc14348 100644 (file)
@@ -141,7 +141,7 @@ class bdist_wininst(Command):
             target_version = self.target_version
             if not target_version:
                 assert self.skip_build, "Should have already checked this"
-                target_version = sys.version[0:3]
+                target_version = '%d.%d' % sys.version_info[:2]
             plat_specifier = ".%s-%s" % (self.plat_name, target_version)
             build = self.get_finalized_command('build')
             build.build_lib = os.path.join(build.build_base,
index 337dd0bfc1e2006dcccf525f8f869d4946ce4892..c6f52e61e1bc705fa46d81336eb34897e33a0074 100644 (file)
@@ -81,7 +81,7 @@ class build(Command):
                             "--plat-name only supported on Windows (try "
                             "using './configure --help' on your platform)")
 
-        plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
+        plat_specifier = ".%s-%d.%d" % (self.plat_name, *sys.version_info[:2])
 
         # Make it so Python 2.x and Python 2.x with --with-pydebug don't
         # share the same build directories. Doing so confuses the build
@@ -114,7 +114,7 @@ class build(Command):
                                            'temp' + plat_specifier)
         if self.build_scripts is None:
             self.build_scripts = os.path.join(self.build_base,
-                                              'scripts-' + sys.version[0:3])
+                                              'scripts-%d.%d' % sys.version_info[:2])
 
         if self.executable is None:
             self.executable = os.path.normpath(sys.executable)
index 67db007a0247342fabf1d8135112bb582fab37aa..9474e9c5997dd850cdbff7118184722a9bbe38a9 100644 (file)
@@ -290,8 +290,8 @@ class install(Command):
                             'dist_version': self.distribution.get_version(),
                             'dist_fullname': self.distribution.get_fullname(),
                             'py_version': py_version,
-                            'py_version_short': py_version[0:3],
-                            'py_version_nodot': py_version[0] + py_version[2],
+                            'py_version_short': '%d.%d' % sys.version_info[:2],
+                            'py_version_nodot': '%d%d' % sys.version_info[:2],
                             'sys_prefix': prefix,
                             'prefix': prefix,
                             'sys_exec_prefix': exec_prefix,
index c2a7d649c0c58d90193a70cee0635bd6bb31f751..0ddc7367cc608dac2cfb408a08c8b442278a8207 100644 (file)
@@ -21,10 +21,10 @@ class install_egg_info(Command):
 
     def finalize_options(self):
         self.set_undefined_options('install_lib',('install_dir','install_dir'))
-        basename = "%s-%s-py%s.egg-info" % (
+        basename = "%s-%s-py%d.%d.egg-info" % (
             to_filename(safe_name(self.distribution.get_name())),
             to_filename(safe_version(self.distribution.get_version())),
-            sys.version[:3]
+            *sys.version_info[:2]
         )
         self.target = os.path.join(self.install_dir, basename)
         self.outputs = [self.target]
index 573724ddd778d191f56eaadbcc3de822d89deae2..d203f8e42b2078986a84201e9fb659f70866f8c0 100644 (file)
@@ -70,7 +70,7 @@ def get_python_version():
     leaving off the patchlevel.  Sample return values could be '1.5'
     or '2.2'.
     """
-    return sys.version[:3]
+    return '%d.%d' % sys.version_info[:2]
 
 
 def get_python_inc(plat_specific=0, prefix=None):
index 3391f36d4bf275e66e5aacea2d053152cdde7ae5..b020a5ba3569d71ecfdea65934eb6408a64a092a 100644 (file)
@@ -27,7 +27,7 @@ class BuildTestCase(support.TempdirManager,
         # build_platlib is 'build/lib.platform-x.x[-pydebug]'
         # examples:
         #   build/lib.macosx-10.3-i386-2.7
-        plat_spec = '.%s-%s' % (cmd.plat_name, sys.version[0:3])
+        plat_spec = '.%s-%d.%d' % (cmd.plat_name, *sys.version_info[:2])
         if hasattr(sys, 'gettotalrefcount'):
             self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
             plat_spec += '-pydebug'
@@ -42,7 +42,8 @@ class BuildTestCase(support.TempdirManager,
         self.assertEqual(cmd.build_temp, wanted)
 
         # build_scripts is build/scripts-x.x
-        wanted = os.path.join(cmd.build_base, 'scripts-' +  sys.version[0:3])
+        wanted = os.path.join(cmd.build_base,
+                              'scripts-%d.%d' % sys.version_info[:2])
         self.assertEqual(cmd.build_scripts, wanted)
 
         # executable is os.path.normpath(sys.executable)
index 71098f10856a87364015c89d3389c33dc48b0740..ddb2456e9f3239516de8cc31913741f0520cf8cf 100644 (file)
@@ -593,7 +593,7 @@ class WindowsRegistryFinder:
         else:
             registry_key = cls.REGISTRY_KEY
         key = registry_key.format(fullname=fullname,
-                                  sys_version=sys.version[:3])
+                                  sys_version='%d.%d' % sys.version_info[:2])
         try:
             with cls._open_registry(key) as hkey:
                 filepath = _winreg.QueryValue(hkey, '')
index a73298d7157235c30b23fe1605473d3980c86df8..5e5a8aeaa5cd665bc26ab48d008e2ea3f3b1e034 100644 (file)
@@ -1911,10 +1911,10 @@ has the same effect as typing a particular string at the help> prompt.
 
     def intro(self):
         self.output.write('''
-Welcome to Python %s's help utility!
+Welcome to Python {0}'s help utility!
 
 If this is your first time using Python, you should definitely check out
-the tutorial on the Internet at http://docs.python.org/%s/tutorial/.
+the tutorial on the Internet at http://docs.python.org/{0}/tutorial/.
 
 Enter the name of any module, keyword, or topic to get help on writing
 Python programs and using Python modules.  To quit this help utility and
@@ -1924,7 +1924,7 @@ To get a list of available modules, keywords, symbols, or topics, type
 "modules", "keywords", "symbols", or "topics".  Each module also comes
 with a one-line summary of what it does; to list the modules whose name
 or summary contain a given string such as "spam", type "modules spam".
-''' % tuple([sys.version[:3]]*2))
+'''.format('%d.%d' % sys.version_info[:2]))
 
     def list(self, items, columns=4, width=80):
         items = list(sorted(items))
index 13ec8fa43f85c38619bcb107e70c5bc95134f605..56ba7091571f71dc5c03ed3ed422060c36e75e16 100644 (file)
@@ -304,7 +304,7 @@ def getsitepackages(prefixes=None):
 
         if os.sep == '/':
             sitepackages.append(os.path.join(prefix, "lib",
-                                        "python" + sys.version[:3],
+                                        "python%d.%d" % sys.version_info[:2],
                                         "site-packages"))
         else:
             sitepackages.append(prefix)
@@ -317,7 +317,7 @@ def getsitepackages(prefixes=None):
             if framework:
                 sitepackages.append(
                         os.path.join("/Library", framework,
-                            sys.version[:3], "site-packages"))
+                            '%d.%d' % sys.version_info[:2], "site-packages"))
     return sitepackages
 
 def addsitepackages(known_paths, prefixes=None):
index 9c34be0a07e2f16f6e9e50a13d4fbb9423343f28..f18b1bc9580623a5f6af921e59a30da2a68b0649 100644 (file)
@@ -86,8 +86,8 @@ _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
  # FIXME don't rely on sys.version here, its format is an implementation detail
  # of CPython, use sys.version_info or sys.hexversion
 _PY_VERSION = sys.version.split()[0]
-_PY_VERSION_SHORT = sys.version[:3]
-_PY_VERSION_SHORT_NO_DOT = _PY_VERSION[0] + _PY_VERSION[2]
+_PY_VERSION_SHORT = '%d.%d' % sys.version_info[:2]
+_PY_VERSION_SHORT_NO_DOT = '%d%d' % sys.version_info[:2]
 _PREFIX = os.path.normpath(sys.prefix)
 _BASE_PREFIX = os.path.normpath(sys.base_prefix)
 _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
@@ -386,7 +386,7 @@ def _generate_posix_vars():
         module.build_time_vars = vars
         sys.modules[name] = module
 
-    pybuilddir = 'build/lib.%s-%s' % (get_platform(), sys.version[:3])
+    pybuilddir = 'build/lib.%s-%s' % (get_platform(), _PY_VERSION_SHORT)
     if hasattr(sys, "gettotalrefcount"):
         pybuilddir += '-pydebug'
     os.makedirs(pybuilddir, exist_ok=True)
@@ -518,7 +518,7 @@ def get_config_vars(*args):
         _CONFIG_VARS['exec_prefix'] = _EXEC_PREFIX
         _CONFIG_VARS['py_version'] = _PY_VERSION
         _CONFIG_VARS['py_version_short'] = _PY_VERSION_SHORT
-        _CONFIG_VARS['py_version_nodot'] = _PY_VERSION[0] + _PY_VERSION[2]
+        _CONFIG_VARS['py_version_nodot'] = _PY_VERSION_SHORT_NO_DOT
         _CONFIG_VARS['installed_base'] = _BASE_PREFIX
         _CONFIG_VARS['base'] = _PREFIX
         _CONFIG_VARS['installed_platbase'] = _BASE_EXEC_PREFIX
index c893bcf565eb75d857affd0db5c08d0ada9a9970..005b685cc03cd92cba347b7d0881320ce74d1d2e 100644 (file)
@@ -40,7 +40,7 @@ def setup_module(machinery, name, path=None):
     else:
         root = machinery.WindowsRegistryFinder.REGISTRY_KEY
     key = root.format(fullname=name,
-                      sys_version=sys.version[:3])
+                      sys_version='%d.%d' % sys.version_info[:2])
     try:
         with temp_module(name, "a = 1") as location:
             subkey = CreateKey(HKEY_CURRENT_USER, key)
index 6615080c46ebbbce2682591816038043cdc40b76..574e4969ffc3e0355780e0e272383e0c71e4d652 100644 (file)
@@ -238,13 +238,14 @@ class HelperFunctionsTests(unittest.TestCase):
             self.assertEqual(len(dirs), 2)
             wanted = os.path.join('/Library',
                                   sysconfig.get_config_var("PYTHONFRAMEWORK"),
-                                  sys.version[:3],
+                                  '%d.%d' % sys.version_info[:2],
                                   'site-packages')
             self.assertEqual(dirs[1], wanted)
         elif os.sep == '/':
             # OS X non-framwework builds, Linux, FreeBSD, etc
             self.assertEqual(len(dirs), 1)
-            wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3],
+            wanted = os.path.join('xoxo', 'lib',
+                                  'python%d.%d' % sys.version_info[:2],
                                   'site-packages')
             self.assertEqual(dirs[0], wanted)
         else:
index 28b0f6c3e3d26f8725bb9b725930366f216a5d98..f38f52df4d304f50756996c246d692012382d0bd 100644 (file)
@@ -51,7 +51,7 @@ class BaseTest(unittest.TestCase):
             self.include = 'Include'
         else:
             self.bindir = 'bin'
-            self.lib = ('lib', 'python%s' % sys.version[:3])
+            self.lib = ('lib', 'python%d.%d' % sys.version_info[:2])
             self.include = 'include'
         if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in os.environ:
             executable = os.environ['__PYVENV_LAUNCHER__']
index 4c2b9fe0e216d5e8c11b7d1bee4f3488d2678d34..e3eed1613158294c74ad9873f2e10da22b24fe26 100644 (file)
@@ -133,7 +133,7 @@ __all__ = [
 ]
 
 # used in User-Agent header sent
-__version__ = sys.version[:3]
+__version__ = '%d.%d' % sys.version_info[:2]
 
 _opener = None
 def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
index bf428358439fc9887ed176900c180eea942279bd..07a4f03006c70ad5ce6d26ce96b73058ab78439d 100644 (file)
@@ -151,7 +151,7 @@ def escape(s):
     return s.replace(">", "&gt;",)
 
 # used in User-Agent header sent
-__version__ = sys.version[:3]
+__version__ = '%d.%d' % sys.version_info[:2]
 
 # xmlrpc integer limits
 MAXINT =  2**31-1
index 2a687e58c9141b44520db9ad0b07b71525fd051d..6514bf8199bc807db47d6b4129ff32134cd6861f 100644 (file)
@@ -568,7 +568,7 @@ $(BUILDPYTHON):     Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
        $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
 
 platform: $(BUILDPYTHON) pybuilddir.txt
-       $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
+       $(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
 
 # Create build directory and generate the sysconfig build-time data there.
 # pybuilddir.txt contains the name of the build dir and is used for
index 97c4948bcb883b5dcb8bc2f183bb0d4fb2b156a7..3d7aff01e82f2e5e5f423b1434d42be645ea792d 100644 (file)
@@ -888,22 +888,23 @@ const unsigned char _Py_M__importlib_external[] = {
     87,105,110,100,111,119,115,82,101,103,105,115,116,114,121,70,
     105,110,100,101,114,46,95,111,112,101,110,95,114,101,103,105,
     115,116,114,121,99,2,0,0,0,0,0,0,0,6,0,0,
-    0,16,0,0,0,67,0,0,0,115,143,0,0,0,124,0,
+    0,16,0,0,0,67,0,0,0,115,147,0,0,0,124,0,
     0,106,0,0,114,21,0,124,0,0,106,1,0,125,2,0,
     110,9,0,124,0,0,106,2,0,125,2,0,124,2,0,106,
-    3,0,100,1,0,124,1,0,100,2,0,116,4,0,106,5,
-    0,100,0,0,100,3,0,133,2,0,25,131,0,2,125,3,
-    0,121,47,0,124,0,0,106,6,0,124,3,0,131,1,0,
-    143,25,0,125,4,0,116,7,0,106,8,0,124,4,0,100,
-    4,0,131,2,0,125,5,0,87,100,0,0,81,82,88,87,
-    110,22,0,4,116,9,0,107,10,0,114,138,0,1,1,1,
-    100,0,0,83,89,110,1,0,88,124,5,0,83,41,5,78,
-    114,119,0,0,0,90,11,115,121,115,95,118,101,114,115,105,
-    111,110,114,80,0,0,0,114,30,0,0,0,41,10,218,11,
-    68,69,66,85,71,95,66,85,73,76,68,218,18,82,69,71,
-    73,83,84,82,89,95,75,69,89,95,68,69,66,85,71,218,
-    12,82,69,71,73,83,84,82,89,95,75,69,89,114,47,0,
-    0,0,114,7,0,0,0,218,7,118,101,114,115,105,111,110,
+    3,0,100,1,0,124,1,0,100,2,0,100,3,0,116,4,
+    0,106,5,0,100,0,0,100,4,0,133,2,0,25,22,131,
+    0,2,125,3,0,121,47,0,124,0,0,106,6,0,124,3,
+    0,131,1,0,143,25,0,125,4,0,116,7,0,106,8,0,
+    124,4,0,100,5,0,131,2,0,125,5,0,87,100,0,0,
+    81,82,88,87,110,22,0,4,116,9,0,107,10,0,114,142,
+    0,1,1,1,100,0,0,83,89,110,1,0,88,124,5,0,
+    83,41,6,78,114,119,0,0,0,90,11,115,121,115,95,118,
+    101,114,115,105,111,110,122,5,37,100,46,37,100,114,56,0,
+    0,0,114,30,0,0,0,41,10,218,11,68,69,66,85,71,
+    95,66,85,73,76,68,218,18,82,69,71,73,83,84,82,89,
+    95,75,69,89,95,68,69,66,85,71,218,12,82,69,71,73,
+    83,84,82,89,95,75,69,89,114,47,0,0,0,114,7,0,
+    0,0,218,12,118,101,114,115,105,111,110,95,105,110,102,111,
     114,166,0,0,0,114,163,0,0,0,90,10,81,117,101,114,
     121,86,97,108,117,101,114,40,0,0,0,41,6,114,164,0,
     0,0,114,119,0,0,0,90,12,114,101,103,105,115,116,114,
@@ -911,7 +912,7 @@ const unsigned char _Py_M__importlib_external[] = {
     218,8,102,105,108,101,112,97,116,104,114,4,0,0,0,114,
     4,0,0,0,114,5,0,0,0,218,16,95,115,101,97,114,
     99,104,95,114,101,103,105,115,116,114,121,77,2,0,0,115,
-    22,0,0,0,0,2,9,1,12,2,9,1,15,1,22,1,
+    22,0,0,0,0,2,9,1,12,2,9,1,15,1,26,1,
     3,1,18,1,29,1,13,1,9,1,122,38,87,105,110,100,
     111,119,115,82,101,103,105,115,116,114,121,70,105,110,100,101,
     114,46,95,115,101,97,114,99,104,95,114,101,103,105,115,116,
index c0758078f87ec2db7a530e6345372ce59945d54c..389fffd54c933f53f1b3bdc3320670fe2de7779f 100755 (executable)
@@ -218,7 +218,7 @@ def main():
     ishome = os.path.exists(os.path.join(prefix, 'Python', 'ceval.c'))
 
     # locations derived from options
-    version = sys.version[:3]
+    version = '%d.%d' % sys.version_info[:2]
     flagged_version = version + sys.abiflags
     if win:
         extensions_c = 'frozen_extensions.c'
index 8f07559e2105184614c9884d8036976d03032e7b..83bbcd749f4d9d1fa05a6a023f375f64ee03b5e0 100755 (executable)
@@ -36,8 +36,8 @@ option to produce this format (since it is the original v7 Unix format).
 """
 import os, sys
 
-PYTHONLIB = 'libpython'+sys.version[:3]+'.a'
-PC_PYTHONLIB = 'Python'+sys.version[0]+sys.version[2]+'.dll'
+PYTHONLIB = 'libpython%d.%d.a' % sys.version_info[:2]
+PC_PYTHONLIB = 'Python%d%d.dll' % sys.version_info[:2]
 NM = 'nm -p -g %s'                      # For Linux, use "nm -g %s"
 
 def symbols(lib=PYTHONLIB,types=('T','C','D')):
index 930b64a73aeb837ee2ea4eb265d6d5311c34d544..720f56844d4511708c79e239038753ab4d5c7220 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2226,7 +2226,7 @@ def main():
     setup(# PyPI Metadata (PEP 301)
           name = "Python",
           version = sys.version.split()[0],
-          url = "http://www.python.org/%s" % sys.version[:3],
+          url = "http://www.python.org/%d.%d" % sys.version_info[:2],
           maintainer = "Guido van Rossum and the Python community",
           maintainer_email = "python-dev@python.org",
           description = "A high-level object-oriented programming language",