summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-05-17 12:25:31 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-05-17 12:25:31 -0400
commit4892d95db7ff3b2eba8e4fa82f7fef0ad4fdaa4c (patch)
treedadb95206025ec7de47cce8b7c40b1329d4c95c8
parent93b61d39dae9b8179a3bf53da0769c4922a937f9 (diff)
downloadpython-setuptools-bitbucket-4892d95db7ff3b2eba8e4fa82f7fef0ad4fdaa4c.tar.gz
Use PY3 and PY2 throughout
-rwxr-xr-xsetuptools/command/develop.py8
-rwxr-xr-xsetuptools/command/easy_install.py10
-rwxr-xr-xsetuptools/command/egg_info.py2
-rwxr-xr-xsetuptools/command/sdist.py3
-rw-r--r--setuptools/command/test.py9
-rw-r--r--setuptools/dist.py4
-rw-r--r--setuptools/svn_utils.py18
-rw-r--r--setuptools/tests/test_resources.py5
-rw-r--r--setuptools/tests/test_sdist.py24
-rw-r--r--setuptools/tests/test_test.py4
10 files changed, 44 insertions, 43 deletions
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py
index 1d500040..129184ca 100755
--- a/setuptools/command/develop.py
+++ b/setuptools/command/develop.py
@@ -5,6 +5,8 @@ from distutils import log
from distutils.errors import DistutilsError, DistutilsOptionError
import os, sys, setuptools, glob
+from setuptools.compat import PY3
+
class develop(easy_install):
"""Set up package for development"""
@@ -84,7 +86,7 @@ class develop(easy_install):
" installation directory", p, normalize_path(os.curdir))
def install_for_development(self):
- if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
+ if PY3 and getattr(self.distribution, 'use_2to3', False):
# If we run 2to3 we can not do this inplace:
# Ensure metadata is up-to-date
@@ -99,7 +101,7 @@ class develop(easy_install):
self.reinitialize_command('build_ext', inplace=0)
self.run_command('build_ext')
-
+
# Fixup egg-link and easy-install.pth
ei_cmd = self.get_finalized_command("egg_info")
self.egg_path = build_path
@@ -112,7 +114,7 @@ class develop(easy_install):
# Build extensions in-place
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
-
+
self.install_site_py() # ensure that target dir is site-safe
if setuptools.bootstrap_install_from:
self.easy_install(setuptools.bootstrap_install_from)
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index a5f324e3..ad7f4725 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -47,7 +47,7 @@ from setuptools.package_index import PackageIndex
from setuptools.package_index import URL_SCHEME
from setuptools.command import bdist_egg, egg_info
from setuptools.compat import (iteritems, maxsize, basestring, unicode,
- reraise)
+ reraise, PY2, PY3)
from pkg_resources import (
yield_lines, normalize_path, resource_string, ensure_directory,
get_distribution, find_distributions, Environment, Requirement,
@@ -75,7 +75,7 @@ def samefile(p1, p2):
norm_p2 = os.path.normpath(os.path.normcase(p2))
return norm_p1 == norm_p2
-if sys.version_info <= (3,):
+if PY2:
def _to_ascii(s):
return s
def isascii(s):
@@ -1187,7 +1187,7 @@ Please make the appropriate changes for your system and try again."""
f = open(sitepy,'rb')
current = f.read()
# we want str, not bytes
- if sys.version_info >= (3,):
+ if PY3:
current = current.decode()
f.close()
@@ -1409,7 +1409,7 @@ def get_exe_prefixes(exe_filename):
continue
if parts[0].upper() in ('PURELIB','PLATLIB'):
contents = z.read(name)
- if sys.version_info >= (3,):
+ if PY3:
contents = contents.decode()
for pth in yield_lines(contents):
pth = pth.strip().replace('\\','/')
@@ -1855,7 +1855,7 @@ def get_win_launcher(type):
def load_launcher_manifest(name):
manifest = pkg_resources.resource_string(__name__, 'launcher manifest.xml')
- if sys.version_info[0] < 3:
+ if PY2:
return manifest % vars()
else:
return manifest.decode('utf-8') % vars()
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 22501c44..646f9460 100755
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -128,7 +128,7 @@ class egg_info(Command):
to the file.
"""
log.info("writing %s to %s", what, filename)
- if sys.version_info >= (3,):
+ if PY3:
data = data.encode("utf-8")
if not self.dry_run:
f = open(filename, 'wb')
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index 948d27fa..f9a5b7b9 100755
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -8,6 +8,7 @@ import distutils.command.sdist as orig
from distutils.util import convert_path
from distutils import log
from setuptools import svn_utils
+from setuptools.compat import PY3
READMES = ('README', 'README.rst', 'README.txt')
@@ -230,7 +231,7 @@ class sdist(orig.sdist):
manifest = open(self.manifest, 'rbU')
for line in manifest:
# The manifest must contain UTF-8. See #303.
- if sys.version_info >= (3,):
+ if PY3:
try:
line = line.decode('UTF-8')
except UnicodeDecodeError:
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index 7422b719..3c3581a9 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -8,6 +8,7 @@ from pkg_resources import (resource_listdir, resource_exists,
normalize_path, working_set, _namespace_packages, add_activation_listener,
require, EntryPoint)
+from setuptools.compat import PY3
from setuptools.py31compat import unittest_main
@@ -87,10 +88,8 @@ class test(Command):
self.test_runner = getattr(self.distribution, 'test_runner', None)
def with_project_on_sys_path(self, func):
- with_2to3 = (
- sys.version_info >= (3,)
- and getattr(self.distribution, 'use_2to3', False)
- )
+ with_2to3 = PY3 and getattr(self.distribution, 'use_2to3', False)
+
if with_2to3:
# If we run 2to3 we can not do this inplace:
@@ -149,7 +148,7 @@ class test(Command):
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
- if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
+ if PY3 and getattr(self.distribution, 'use_2to3', False):
module = self.test_args[-1].split('.')[0]
if module in _namespace_packages:
del_modules = []
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 59a89236..b8bd7490 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -13,7 +13,7 @@ from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsSetupError)
from setuptools.depends import Require
-from setuptools.compat import numeric_types, basestring
+from setuptools.compat import numeric_types, basestring, PY2
import pkg_resources
def _get_unpatched(cls):
@@ -629,7 +629,7 @@ class Distribution(_Distribution):
"""
import sys
- if sys.version_info < (3,) or self.help_commands:
+ if PY2 or self.help_commands:
return _Distribution.handle_display_options(self, option_order)
# Stdout may be StringIO (e.g. in tests)
diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py
index 8fc552fa..2dcfd899 100644
--- a/setuptools/svn_utils.py
+++ b/setuptools/svn_utils.py
@@ -8,7 +8,7 @@ import locale
import codecs
import unicodedata
import warnings
-from setuptools.compat import unicode
+from setuptools.compat import unicode, PY2
from setuptools.py31compat import TemporaryDirectory
from xml.sax.saxutils import unescape
@@ -60,7 +60,7 @@ def _get_target_property(target):
def _get_xml_data(decoded_str):
- if sys.version_info < (3, 0):
+ if PY2:
#old versions want an encoded string
data = decoded_str.encode('utf-8')
else:
@@ -180,12 +180,12 @@ def parse_external_prop(lines):
if not line:
continue
- if sys.version_info < (3, 0):
+ if PY2:
#shlex handles NULLs just fine and shlex in 2.7 tries to encode
#as ascii automatiically
line = line.encode('utf-8')
line = shlex.split(line)
- if sys.version_info < (3, 0):
+ if PY2:
line = [x.decode('utf-8') for x in line]
#EXT_FOLDERNAME is either the first or last depending on where
@@ -232,13 +232,13 @@ class SvnInfo(object):
@staticmethod
def get_svn_version():
# Temp config directory should be enough to check for repository
- # This is needed because .svn always creates .subversion and
+ # This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with TemporaryDirectory() as tempdir:
- code, data = _run_command(['svn',
+ code, data = _run_command(['svn',
'--config-dir', tempdir,
- '--version',
+ '--version',
'--quiet'])
if code == 0 and data:
@@ -258,11 +258,11 @@ class SvnInfo(object):
normdir = os.path.normpath(dirname)
# Temp config directory should be enough to check for repository
- # This is needed because .svn always creates .subversion and
+ # This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with TemporaryDirectory() as tempdir:
- code, data = _run_command(['svn',
+ code, data = _run_command(['svn',
'--config-dir', tempdir,
'info', normdir])
diff --git a/setuptools/tests/test_resources.py b/setuptools/tests/test_resources.py
index c9fcf76c..443905cc 100644
--- a/setuptools/tests/test_resources.py
+++ b/setuptools/tests/test_resources.py
@@ -15,7 +15,7 @@ from pkg_resources import (parse_requirements, VersionConflict, parse_version,
from setuptools.command.easy_install import (get_script_header, is_sh,
nt_quote_arg)
-from setuptools.compat import StringIO, iteritems
+from setuptools.compat import StringIO, iteritems, PY3
try:
frozenset
@@ -522,8 +522,7 @@ class ScriptHeaderTests(TestCase):
def test_get_script_header_jython_workaround(self):
# This test doesn't work with Python 3 in some locales
- if (sys.version_info >= (3,) and os.environ.get("LC_CTYPE")
- in (None, "C", "POSIX")):
+ if PY3 and os.environ.get("LC_CTYPE") in (None, "C", "POSIX"):
return
class java:
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index ada86189..231b40d0 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -12,7 +12,7 @@ import re
from setuptools.tests import environment, test_svn
from setuptools.tests.py26compat import skipIf
-from setuptools.compat import StringIO, unicode
+from setuptools.compat import StringIO, unicode, PY3, PY2
from setuptools.tests.py26compat import skipIf
from setuptools.command.sdist import sdist, walk_revctrl
from setuptools.command.egg_info import manifest_maker
@@ -34,7 +34,7 @@ setup(**%r)
""" % SETUP_ATTRS
-if sys.version_info >= (3,):
+if PY3:
LATIN1_FILENAME = 'smörbröd.py'.encode('latin-1')
else:
LATIN1_FILENAME = 'sm\xf6rbr\xf6d.py'
@@ -52,14 +52,14 @@ def unquiet():
# Fake byte literals for Python <= 2.5
def b(s, encoding='utf-8'):
- if sys.version_info >= (3,):
+ if PY3:
return s.encode(encoding)
return s
# Convert to POSIX path
def posix(path):
- if sys.version_info >= (3,) and not isinstance(path, str):
+ if PY3 and not isinstance(path, str):
return path.replace(os.sep.encode('ascii'), b('/'))
else:
return path.replace(os.sep, '/')
@@ -156,14 +156,14 @@ class TestSdistTest(unittest.TestCase):
self.fail(e)
# The manifest should contain the UTF-8 filename
- if sys.version_info < (3,):
+ if PY2:
fs_enc = sys.getfilesystemencoding()
filename = filename.decode(fs_enc)
self.assertTrue(posix(filename) in u_contents)
# Python 3 only
- if sys.version_info >= (3,):
+ if PY3:
def test_write_manifest_allows_utf8_filenames(self):
# Test for #303.
@@ -281,12 +281,12 @@ class TestSdistTest(unittest.TestCase):
unquiet()
# The filelist should contain the UTF-8 filename
- if sys.version_info >= (3,):
+ if PY3:
filename = filename.decode('utf-8')
self.assertTrue(filename in cmd.filelist.files)
# Python 3 only
- if sys.version_info >= (3,):
+ if PY3:
def test_read_manifest_skips_non_utf8_filenames(self):
# Test for #303.
@@ -328,7 +328,7 @@ class TestSdistTest(unittest.TestCase):
filename = filename.decode('latin-1')
self.assertFalse(filename in cmd.filelist.files)
- @skipIf(sys.version_info >= (3,) and locale.getpreferredencoding() != 'UTF-8',
+ @skipIf(PY3 and locale.getpreferredencoding() != 'UTF-8',
'Unittest fails if locale is not utf-8 but the manifests is recorded correctly')
def test_sdist_with_utf8_encoded_filename(self):
# Test for #303.
@@ -350,7 +350,7 @@ class TestSdistTest(unittest.TestCase):
if sys.platform == 'darwin':
filename = decompose(filename)
- if sys.version_info >= (3,):
+ if PY3:
fs_enc = sys.getfilesystemencoding()
if sys.platform == 'win32':
@@ -385,7 +385,7 @@ class TestSdistTest(unittest.TestCase):
finally:
unquiet()
- if sys.version_info >= (3,):
+ if PY3:
#not all windows systems have a default FS encoding of cp1252
if sys.platform == 'win32':
# Latin-1 is similar to Windows-1252 however
@@ -408,7 +408,7 @@ class TestSdistTest(unittest.TestCase):
try:
# fs_enc should match how one is expect the decoding to
# be proformed for the manifest output.
- fs_enc = sys.getfilesystemencoding()
+ fs_enc = sys.getfilesystemencoding()
filename.decode(fs_enc)
self.assertTrue(filename in cmd.filelist.files)
except UnicodeDecodeError:
diff --git a/setuptools/tests/test_test.py b/setuptools/tests/test_test.py
index f85123b0..df92085e 100644
--- a/setuptools/tests/test_test.py
+++ b/setuptools/tests/test_test.py
@@ -10,7 +10,7 @@ import tempfile
import unittest
from distutils.errors import DistutilsError
-from setuptools.compat import StringIO
+from setuptools.compat import StringIO, PY2
from setuptools.command.test import test
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
@@ -34,7 +34,7 @@ except ImportError:
__path__ = extend_path(__path__, __name__)
"""
# Make sure this is Latin-1 binary, before writing:
-if sys.version_info < (3,):
+if PY2:
NS_INIT = NS_INIT.decode('UTF-8')
NS_INIT = NS_INIT.encode('Latin-1')