[Python-checkins] distutils2: Use sys.version_info instead of sys.version.
eric.araujo
python-checkins at python.org
Fri Feb 10 05:11:17 CET 2012
http://hg.python.org/distutils2/rev/0cc1fbbb473d
changeset: 1282:0cc1fbbb473d
user: Éric Araujo <merwok at netwok.org>
date: Thu Feb 09 19:41:19 2012 +0100
summary:
Use sys.version_info instead of sys.version.
The contents of this attribute are an implementation detail, as
documented for #9442, so we should not parse it, to support non-CPython
VMs 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 d2.markers).
Other remaining uses are found in d2.compiler and could be replaced by
the platform module (which also parses sys.version, but then it wouldn’t
be my fault :)
files:
distutils2/command/bdist_msi.py | 2 +-
distutils2/command/bdist_wininst.py | 2 +-
distutils2/command/build.py | 6 +++---
distutils2/command/install_dist.py | 2 +-
distutils2/compiler/cygwinccompiler.py | 4 ++++
distutils2/create.py | 2 +-
distutils2/markers.py | 4 +++-
distutils2/pypi/simple.py | 4 ++--
distutils2/tests/support.py | 6 ++++--
distutils2/tests/test_command_build.py | 5 +++--
distutils2/tests/test_command_build_ext.py | 6 +++---
distutils2/tests/test_command_install_dist.py | 4 ++--
distutils2/tests/test_mixin2to3.py | 8 ++++----
distutils2/tests/test_util.py | 4 ++--
runtests.py | 2 +-
setup.py | 2 +-
16 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/distutils2/command/bdist_msi.py b/distutils2/command/bdist_msi.py
--- a/distutils2/command/bdist_msi.py
+++ b/distutils2/command/bdist_msi.py
@@ -203,7 +203,7 @@
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,
diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py
--- a/distutils2/command/bdist_wininst.py
+++ b/distutils2/command/bdist_wininst.py
@@ -137,7 +137,7 @@
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,
diff --git a/distutils2/command/build.py b/distutils2/command/build.py
--- a/distutils2/command/build.py
+++ b/distutils2/command/build.py
@@ -82,8 +82,8 @@
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 @@
'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)
diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py
--- a/distutils2/command/install_dist.py
+++ b/distutils2/command/install_dist.py
@@ -255,7 +255,7 @@
# $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')
diff --git a/distutils2/compiler/cygwinccompiler.py b/distutils2/compiler/cygwinccompiler.py
--- a/distutils2/compiler/cygwinccompiler.py
+++ b/distutils2/compiler/cygwinccompiler.py
@@ -56,6 +56,10 @@
from distutils2.util import get_compiler_versions
from distutils2._backport 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
diff --git a/distutils2/create.py b/distutils2/create.py
--- a/distutils2/create.py
+++ b/distutils2/create.py
@@ -377,7 +377,7 @@
('long_description', 'description'),
('url', 'home_page'),
('platforms', 'platform'))
- if sys.version >= '2.5':
+ if sys.version_info[:2] >= (2, 5):
labels += (
('provides', 'provides-dist'),
('obsoletes', 'obsoletes-dist'),
diff --git a/distutils2/markers.py b/distutils2/markers.py
--- a/distutils2/markers.py
+++ b/distutils2/markers.py
@@ -28,7 +28,9 @@
# 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(),
diff --git a/distutils2/pypi/simple.py b/distutils2/pypi/simple.py
--- a/distutils2/pypi/simple.py
+++ b/distutils2/pypi/simple.py
@@ -34,8 +34,8 @@
DEFAULT_SIMPLE_INDEX_URL = "http://a.pypi.python.org/simple/"
DEFAULT_HOSTS = ("*",)
SOCKET_TIMEOUT = 15
-USER_AGENT = "Python-urllib/%s distutils2/%s" % (
- sys.version[:3], distutils2_version)
+USER_AGENT = "Python-urllib/%s.%s distutils2/%s" % (
+ sys.version_info[0], sys.version_info[1], distutils2_version)
# -- Regexps -------------------------------------------------
EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.]+)$')
diff --git a/distutils2/tests/support.py b/distutils2/tests/support.py
--- a/distutils2/tests/support.py
+++ b/distutils2/tests/support.py
@@ -63,8 +63,9 @@
# misc. functions and decorators
'fake_dec', 'create_distribution', 'use_command',
'copy_xxmodule_c', 'fixup_build_ext',
+ 'requires_py26_min', 'skip_2to3_optimize',
# imported from this module for backport purposes
- 'unittest', 'requires_zlib', 'skip_2to3_optimize', 'skip_unless_symlink',
+ 'unittest', 'requires_zlib', 'skip_unless_symlink',
]
@@ -402,10 +403,11 @@
skip_unless_symlink = unittest.skip(
'requires test.test_support.skip_unless_symlink')
-
skip_2to3_optimize = unittest.skipUnless(__debug__,
"2to3 doesn't work under -O")
+requires_py26_min = unittest.skipIf(sys.version_info[:2] < (2, 6),
+ 'requires Python 2.6 or higher')
requires_zlib = unittest.skipUnless(zlib, 'requires zlib')
diff --git a/distutils2/tests/test_command_build.py b/distutils2/tests/test_command_build.py
--- a/distutils2/tests/test_command_build.py
+++ b/distutils2/tests/test_command_build.py
@@ -26,7 +26,8 @@
# 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 @@
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)
diff --git a/distutils2/tests/test_command_build_ext.py b/distutils2/tests/test_command_build_ext.py
--- a/distutils2/tests/test_command_build_ext.py
+++ b/distutils2/tests/test_command_build_ext.py
@@ -19,12 +19,12 @@
def setUp(self):
super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp()
- if sys.version > "2.6":
+ if sys.version_info[:2] >= (2, 6):
self.old_user_base = site.USER_BASE
site.USER_BASE = self.mkdtemp()
def tearDown(self):
- if sys.version > "2.6":
+ if sys.version_info[:2] >= (2, 6):
site.USER_BASE = self.old_user_base
super(BuildExtTestCase, self).tearDown()
@@ -85,7 +85,7 @@
# make sure we get some library dirs under solaris
self.assertGreater(len(cmd.library_dirs), 0)
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
def test_user_site(self):
dist = Distribution({'name': 'xx'})
cmd = build_ext(dist)
diff --git a/distutils2/tests/test_command_install_dist.py b/distutils2/tests/test_command_install_dist.py
--- a/distutils2/tests/test_command_install_dist.py
+++ b/distutils2/tests/test_command_install_dist.py
@@ -72,7 +72,7 @@
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
check_path(cmd.install_data, destination)
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
def test_user_site(self):
# test install with --user
# preparing the environment for the test
@@ -172,7 +172,7 @@
cmd.home = 'home'
self.assertRaises(PackagingOptionError, cmd.finalize_options)
- if sys.version >= '2.6':
+ if sys.version_info[:2] >= (2, 6):
# can't combine user with with prefix/exec_prefix/home or
# install_(plat)base
cmd.prefix = None
diff --git a/distutils2/tests/test_mixin2to3.py b/distutils2/tests/test_mixin2to3.py
--- a/distutils2/tests/test_mixin2to3.py
+++ b/distutils2/tests/test_mixin2to3.py
@@ -29,9 +29,9 @@
converted = fp.read()
finally:
fp.close()
- self.assertMultiLineEqual(wanted, converted)
+ self.assertMultiLineEqual(converted, wanted)
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
def test_conversion(self):
# check that code and doctests get converted
self.check('''\
@@ -57,7 +57,7 @@
''', # 2to3 adds a newline here
files=[self.filename])
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
def test_doctests_conversion(self):
# check that doctest files are converted
self.check('''\
@@ -75,7 +75,7 @@
''',
doctests=[self.filename])
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
def test_additional_fixers(self):
# make sure the fixers argument works
self.check("""\
diff --git a/distutils2/tests/test_util.py b/distutils2/tests/test_util.py
--- a/distutils2/tests/test_util.py
+++ b/distutils2/tests/test_util.py
@@ -417,7 +417,7 @@
self.assertRaises(ImportError, resolve_name, 'a.b.Spam')
self.assertRaises(ImportError, resolve_name, 'a.b.c.Spam')
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
@support.skip_2to3_optimize
def test_run_2to3_on_code(self):
content = "print 'test'"
@@ -432,7 +432,7 @@
file_handle.close()
self.assertEqual(new_content, converted_content)
- @unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
+ @support.requires_py26_min
@support.skip_2to3_optimize
def test_run_2to3_on_doctests(self):
# to check if text files containing doctests only get converted.
diff --git a/runtests.py b/runtests.py
--- a/runtests.py
+++ b/runtests.py
@@ -215,7 +215,7 @@
if __name__ == "__main__":
- if sys.version < '2.5':
+ if sys.version_info[:2] < (2, 5):
try:
from distutils2._backport import hashlib
except ImportError:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -208,6 +208,6 @@
return exts
setup_kwargs = cfg_to_args('setup.cfg')
-if sys.version < '2.5':
+if sys.version_info[:2] < (2, 5):
setup_kwargs['ext_modules'] = prepare_hashlib_extensions()
setup(**setup_kwargs)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list