Fix for Python 4: replace unsafe six.PY3 with PY2
This commit is contained in:
parent
7e97def477
commit
796abd8dbe
|
@ -113,7 +113,7 @@ class build_ext(_build_ext):
|
|||
if fullname in self.ext_map:
|
||||
ext = self.ext_map[fullname]
|
||||
use_abi3 = (
|
||||
six.PY3
|
||||
not six.PY2
|
||||
and getattr(ext, 'py_limited_api')
|
||||
and get_abi3_suffix()
|
||||
)
|
||||
|
|
|
@ -108,7 +108,7 @@ class develop(namespaces.DevelopInstaller, easy_install):
|
|||
return path_to_setup
|
||||
|
||||
def install_for_development(self):
|
||||
if six.PY3 and getattr(self.distribution, 'use_2to3', False):
|
||||
if not six.PY2 and getattr(self.distribution, 'use_2to3', False):
|
||||
# If we run 2to3 we can not do this inplace:
|
||||
|
||||
# Ensure metadata is up-to-date
|
||||
|
|
|
@ -1567,7 +1567,7 @@ def get_exe_prefixes(exe_filename):
|
|||
continue
|
||||
if parts[0].upper() in ('PURELIB', 'PLATLIB'):
|
||||
contents = z.read(name)
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
contents = contents.decode()
|
||||
for pth in yield_lines(contents):
|
||||
pth = pth.strip().replace('\\', '/')
|
||||
|
|
|
@ -266,7 +266,7 @@ class egg_info(InfoCommon, Command):
|
|||
to the file.
|
||||
"""
|
||||
log.info("writing %s to %s", what, filename)
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
data = data.encode("utf-8")
|
||||
if not self.dry_run:
|
||||
f = open(filename, 'wb')
|
||||
|
|
|
@ -207,7 +207,7 @@ class sdist(sdist_add_defaults, orig.sdist):
|
|||
manifest = open(self.manifest, 'rb')
|
||||
for line in manifest:
|
||||
# The manifest must contain UTF-8. See #303.
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
try:
|
||||
line = line.decode('UTF-8')
|
||||
except UnicodeDecodeError:
|
||||
|
|
|
@ -129,7 +129,7 @@ class test(Command):
|
|||
|
||||
@contextlib.contextmanager
|
||||
def project_on_sys_path(self, include_dists=[]):
|
||||
with_2to3 = six.PY3 and getattr(self.distribution, 'use_2to3', False)
|
||||
with_2to3 = not six.PY2 and getattr(self.distribution, 'use_2to3', False)
|
||||
|
||||
if with_2to3:
|
||||
# If we run 2to3 we can not do this inplace:
|
||||
|
@ -240,7 +240,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 six.PY3 and getattr(self.distribution, 'use_2to3', False):
|
||||
if not six.PY2 and getattr(self.distribution, 'use_2to3', False):
|
||||
module = self.test_suite.split('.')[0]
|
||||
if module in _namespace_packages:
|
||||
del_modules = []
|
||||
|
|
|
@ -24,7 +24,7 @@ from .upload import upload
|
|||
|
||||
|
||||
def _encode(s):
|
||||
errors = 'surrogateescape' if six.PY3 else 'strict'
|
||||
errors = 'strict' if six.PY2 else 'surrogateescape'
|
||||
return s.encode('utf-8', errors)
|
||||
|
||||
|
||||
|
@ -153,7 +153,7 @@ class upload_docs(upload):
|
|||
# set up the authentication
|
||||
credentials = _encode(self.username + ':' + self.password)
|
||||
credentials = standard_b64encode(credentials)
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
credentials = credentials.decode('ascii')
|
||||
auth = "Basic " + credentials
|
||||
|
||||
|
|
|
@ -571,7 +571,7 @@ class Distribution(_Distribution):
|
|||
from setuptools.extern.six.moves.configparser import ConfigParser
|
||||
|
||||
# Ignore install directory options if we have a venv
|
||||
if six.PY3 and sys.prefix != sys.base_prefix:
|
||||
if not six.PY2 and sys.prefix != sys.base_prefix:
|
||||
ignore_options = [
|
||||
'install-base', 'install-platbase', 'install-lib',
|
||||
'install-platlib', 'install-purelib', 'install-headers',
|
||||
|
@ -593,7 +593,7 @@ class Distribution(_Distribution):
|
|||
with io.open(filename, encoding='utf-8') as reader:
|
||||
if DEBUG:
|
||||
self.announce(" reading {filename}".format(**locals()))
|
||||
(parser.read_file if six.PY3 else parser.readfp)(reader)
|
||||
(parser.readfp if six.PY2 else parser.read_file)(reader)
|
||||
for section in parser.sections():
|
||||
options = parser.options(section)
|
||||
opt_dict = self.get_option_dict(section)
|
||||
|
@ -636,7 +636,7 @@ class Distribution(_Distribution):
|
|||
|
||||
Ref #1653
|
||||
"""
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
return val
|
||||
try:
|
||||
return val.encode()
|
||||
|
|
|
@ -95,7 +95,7 @@ class TestDevelop:
|
|||
with io.open(fn) as init_file:
|
||||
init = init_file.read().strip()
|
||||
|
||||
expected = 'print("foo")' if six.PY3 else 'print "foo"'
|
||||
expected = 'print "foo"' if six.PY2 else 'print("foo")'
|
||||
assert init == expected
|
||||
|
||||
def test_console_scripts(self, tmpdir):
|
||||
|
@ -161,7 +161,7 @@ class TestNamespaces:
|
|||
reason="https://github.com/pypa/setuptools/issues/851",
|
||||
)
|
||||
@pytest.mark.skipif(
|
||||
platform.python_implementation() == 'PyPy' and six.PY3,
|
||||
platform.python_implementation() == 'PyPy' and not six.PY2,
|
||||
reason="https://github.com/pypa/setuptools/issues/1202",
|
||||
)
|
||||
def test_namespace_package_importable(self, tmpdir):
|
||||
|
|
|
@ -51,7 +51,7 @@ def quiet():
|
|||
|
||||
# Convert to POSIX path
|
||||
def posix(path):
|
||||
if six.PY3 and not isinstance(path, str):
|
||||
if not six.PY2 and not isinstance(path, str):
|
||||
return path.replace(os.sep.encode('ascii'), b'/')
|
||||
else:
|
||||
return path.replace(os.sep, '/')
|
||||
|
@ -329,7 +329,7 @@ class TestSdistTest:
|
|||
cmd.read_manifest()
|
||||
|
||||
# The filelist should contain the UTF-8 filename
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
filename = filename.decode('utf-8')
|
||||
assert filename in cmd.filelist.files
|
||||
|
||||
|
@ -383,7 +383,7 @@ class TestSdistTest:
|
|||
if sys.platform == 'darwin':
|
||||
filename = decompose(filename)
|
||||
|
||||
if six.PY3:
|
||||
if not six.PY2:
|
||||
fs_enc = sys.getfilesystemencoding()
|
||||
|
||||
if sys.platform == 'win32':
|
||||
|
@ -425,7 +425,19 @@ class TestSdistTest:
|
|||
with quiet():
|
||||
cmd.run()
|
||||
|
||||
if six.PY3:
|
||||
if six.PY2:
|
||||
# Under Python 2 there seems to be no decoded string in the
|
||||
# filelist. However, due to decode and encoding of the
|
||||
# file name to get utf-8 Manifest the latin1 maybe excluded
|
||||
try:
|
||||
# fs_enc should match how one is expect the decoding to
|
||||
# be proformed for the manifest output.
|
||||
fs_enc = sys.getfilesystemencoding()
|
||||
filename.decode(fs_enc)
|
||||
assert filename in cmd.filelist.files
|
||||
except UnicodeDecodeError:
|
||||
filename not in cmd.filelist.files
|
||||
else:
|
||||
# not all windows systems have a default FS encoding of cp1252
|
||||
if sys.platform == 'win32':
|
||||
# Latin-1 is similar to Windows-1252 however
|
||||
|
@ -440,18 +452,6 @@ class TestSdistTest:
|
|||
# The Latin-1 filename should have been skipped
|
||||
filename = filename.decode('latin-1')
|
||||
filename not in cmd.filelist.files
|
||||
else:
|
||||
# Under Python 2 there seems to be no decoded string in the
|
||||
# filelist. However, due to decode and encoding of the
|
||||
# file name to get utf-8 Manifest the latin1 maybe excluded
|
||||
try:
|
||||
# fs_enc should match how one is expect the decoding to
|
||||
# be proformed for the manifest output.
|
||||
fs_enc = sys.getfilesystemencoding()
|
||||
filename.decode(fs_enc)
|
||||
assert filename in cmd.filelist.files
|
||||
except UnicodeDecodeError:
|
||||
filename not in cmd.filelist.files
|
||||
|
||||
def test_pyproject_toml_in_sdist(self, tmpdir):
|
||||
"""
|
||||
|
|
|
@ -15,7 +15,7 @@ class TestEdit:
|
|||
def parse_config(filename):
|
||||
parser = configparser.ConfigParser()
|
||||
with io.open(filename, encoding='utf-8') as reader:
|
||||
(parser.read_file if six.PY3 else parser.readfp)(reader)
|
||||
(parser.readfp if six.PY2 else parser.read_file)(reader)
|
||||
return parser
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue