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