summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-01-11 23:28:50 -0500
committerGitHub <noreply@github.com>2020-01-11 23:28:50 -0500
commit70b3ec0bf0f61d6b7de1beff4bad4b845d836100 (patch)
tree216f8873ad05d29714c19d079c74e7fa5b8e94c9
parent7e97def47723303fafabe48b22168bbc11bb4821 (diff)
parentb84a0997af9b5ba757d39b0631545f53d03bc741 (diff)
downloadpython-setuptools-git-70b3ec0bf0f61d6b7de1beff4bad4b845d836100.tar.gz
Merge pull request #1959 from hugovk/fix-flake8-2020
Fix for Python 4: replace unsafe six.PY3 with PY2
-rw-r--r--changelog.d/1959.change.rst1
-rw-r--r--setuptools/command/build_ext.py2
-rw-r--r--setuptools/command/develop.py2
-rw-r--r--setuptools/command/easy_install.py2
-rw-r--r--setuptools/command/egg_info.py2
-rw-r--r--setuptools/command/sdist.py2
-rw-r--r--setuptools/command/test.py4
-rw-r--r--setuptools/command/upload_docs.py4
-rw-r--r--setuptools/dist.py6
-rw-r--r--setuptools/tests/test_develop.py4
-rw-r--r--setuptools/tests/test_sdist.py32
-rw-r--r--setuptools/tests/test_setopt.py2
12 files changed, 32 insertions, 31 deletions
diff --git a/changelog.d/1959.change.rst b/changelog.d/1959.change.rst
new file mode 100644
index 00000000..c0cc8975
--- /dev/null
+++ b/changelog.d/1959.change.rst
@@ -0,0 +1 @@
+Fix for Python 4: replace unsafe six.PY3 with six.PY2
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py
index daa8e4fe..1b51e040 100644
--- a/setuptools/command/build_ext.py
+++ b/setuptools/command/build_ext.py
@@ -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()
)
diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py
index 009e4f93..b5619246 100644
--- a/setuptools/command/develop.py
+++ b/setuptools/command/develop.py
@@ -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
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 09066f8c..426301d6 100644
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -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('\\', '/')
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 5d8f451e..a5c5a2fc 100644
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -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')
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index a851453f..8c3438ea 100644
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -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:
diff --git a/setuptools/command/test.py b/setuptools/command/test.py
index c148b38d..f6470e9c 100644
--- a/setuptools/command/test.py
+++ b/setuptools/command/test.py
@@ -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 = []
diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py
index 07aa564a..130a0cb6 100644
--- a/setuptools/command/upload_docs.py
+++ b/setuptools/command/upload_docs.py
@@ -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
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 1ba262ec..fe5adf46 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -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()
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py
index 00d4bd9a..792975fd 100644
--- a/setuptools/tests/test_develop.py
+++ b/setuptools/tests/test_develop.py
@@ -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):
diff --git a/setuptools/tests/test_sdist.py b/setuptools/tests/test_sdist.py
index 8538dd24..0bea53df 100644
--- a/setuptools/tests/test_sdist.py
+++ b/setuptools/tests/test_sdist.py
@@ -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):
"""
diff --git a/setuptools/tests/test_setopt.py b/setuptools/tests/test_setopt.py
index 3fb04fb4..1b038954 100644
--- a/setuptools/tests/test_setopt.py
+++ b/setuptools/tests/test_setopt.py
@@ -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