]> granicus.if.org Git - python/commitdiff
Use sys.version_info instead of sys.version in packaging.
authorÉric Araujo <merwok@netwok.org>
Fri, 10 Feb 2012 04:20:53 +0000 (05:20 +0100)
committerÉric Araujo <merwok@netwok.org>
Fri, 10 Feb 2012 04:20:53 +0000 (05:20 +0100)
The contents of this attribute are an implementation detail, as
documented for #9442, so we should not parse it, to support non-CPython
VMs with distutils2 in the future.

Unfortunately, one use comes directly from PEP 345, so an edit will have
to be agreed before fixing the code (see comment in p7g.markers).

Other remaining uses are found in p7g.compiler and could be replaced by
the platform module (which also parses sys.version, but then it wouldn’t
be my fault :)

Lib/packaging/command/bdist_msi.py
Lib/packaging/command/bdist_wininst.py
Lib/packaging/command/build.py
Lib/packaging/command/install_dist.py
Lib/packaging/compiler/cygwinccompiler.py
Lib/packaging/markers.py
Lib/packaging/pypi/simple.py
Lib/packaging/tests/test_command_build.py

index 4f8eca6cc453cd1ea1722dac101e0cd1124fb6e8..995eec57e5ae597e4a4cd9811ca5b3dadb890f0b 100644 (file)
@@ -7,9 +7,8 @@ import sys
 import os
 import msilib
 
-
-from sysconfig import get_python_version
 from shutil import rmtree
+from sysconfig import get_python_version
 from packaging.command.cmd import Command
 from packaging.version import NormalizedVersion
 from packaging.errors import PackagingOptionError
@@ -204,7 +203,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 = '%s.%s' % 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 4e6b79ebe2e15d81a554ae30099503ab36bf5046..3c66360ecdcaddd5f0e48bae46ff803cecdd6fb9 100644 (file)
@@ -136,7 +136,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 = '%s.%s' % 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 2e5eb8b52f84f6ef348a0b5661db72c821aa00c7..fcb50df4e49e1356b16090dad2870b7eaf06e0d0 100644 (file)
@@ -82,8 +82,8 @@ class build(Command):
                 raise PackagingOptionError(
                             "--plat-name only supported on Windows (try "
                             "using './configure --help' on your platform)")
-
-        plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
+        pyversion = '%s.%s' % sys.version_info[:2]
+        plat_specifier = ".%s-%s" % (self.plat_name, pyversion)
 
         # 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
@@ -116,7 +116,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-' + pyversion)
 
         if self.executable is None:
             self.executable = os.path.normpath(sys.executable)
index c54da6f3dfa0a67cccbea8addbaa69f624ce20aa..8388dc9fe0bd743de1c0351a4c3a201e41ebc39e 100644 (file)
@@ -242,7 +242,7 @@ class install_dist(Command):
         # $platbase in the other installation directories and not worry
         # about needing recursive variable expansion (shudder).
 
-        py_version = sys.version.split()[0]
+        py_version = '%s.%s' % sys.version_info[:2]
         prefix, exec_prefix, srcdir, projectbase = get_config_vars(
             'prefix', 'exec_prefix', 'srcdir', 'projectbase')
 
index 3eec067481fbac240481f38d85ce3e65e08f2b91..95526676ff08cf39ce8eaff0a33446c0c57f3268 100644 (file)
@@ -56,6 +56,10 @@ from packaging.errors import PackagingExecError, CompileError, UnknownFileError
 from packaging.util import get_compiler_versions
 import sysconfig
 
+# TODO use platform instead of sys.version
+# (platform does unholy sys.version parsing too, but at least it gives other
+# VMs a chance to override the returned values)
+
 
 def get_msvcr():
     """Include the appropriate MSVC runtime library if Python was built
index 4bbac7eca729b08dbb2133c91e8839a57e0fae5f..63fdc1900d7e72fadfd34fcf679ca8f1179bf070 100644 (file)
@@ -1,11 +1,10 @@
 """Parser for the environment markers micro-language defined in PEP 345."""
 
+import os
 import sys
 import platform
-import os
-
-from tokenize import tokenize, NAME, OP, STRING, ENDMARKER, ENCODING
 from io import BytesIO
+from tokenize import tokenize, NAME, OP, STRING, ENDMARKER, ENCODING
 
 __all__ = ['interpret']
 
@@ -27,12 +26,15 @@ def _operate(operation, x, y):
 
 # restricted set of variables
 _VARS = {'sys.platform': sys.platform,
-         'python_version': sys.version[:3],
+         'python_version': '%s.%s' % sys.version_info[:2],
+         # FIXME parsing sys.platform is not reliable, but there is no other
+         # way to get e.g. 2.7.2+, and the PEP is defined with sys.version
          'python_full_version': sys.version.split(' ', 1)[0],
          'os.name': os.name,
          'platform.version': platform.version(),
          'platform.machine': platform.machine(),
-         'platform.python_implementation': platform.python_implementation()}
+         'platform.python_implementation': platform.python_implementation(),
+        }
 
 
 class _Operation:
index 44d98e10e543325a944731d9a5a0214680afbc0a..e26d55d002809ce5f7ffd2eb618c43ee05120a09 100644 (file)
@@ -35,8 +35,8 @@ __all__ = ['Crawler', 'DEFAULT_SIMPLE_INDEX_URL']
 DEFAULT_SIMPLE_INDEX_URL = "http://a.pypi.python.org/simple/"
 DEFAULT_HOSTS = ("*",)
 SOCKET_TIMEOUT = 15
-USER_AGENT = "Python-urllib/%s packaging/%s" % (
-    sys.version[:3], packaging_version)
+USER_AGENT = "Python-urllib/%s.%s packaging/%s" % (
+    sys.version_info[0], sys.version_info[1], packaging_version)
 
 # -- Regexps -------------------------------------------------
 EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.]+)$')
index 91fbe42a0d85d71e0f976f9d2bd7f7ef0808692f..280d709d8d0551d27e759962f903d078a7d56be0 100644 (file)
@@ -26,7 +26,8 @@ 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])
+        pyversion = '%s.%s' % sys.version_info[:2]
+        plat_spec = '.%s-%s' % (cmd.plat_name, pyversion)
         if hasattr(sys, 'gettotalrefcount'):
             self.assertTrue(cmd.build_platlib.endswith('-pydebug'))
             plat_spec += '-pydebug'
@@ -41,7 +42,7 @@ 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-' + pyversion)
         self.assertEqual(cmd.build_scripts, wanted)
 
         # executable is os.path.normpath(sys.executable)