Commit 5f510913 authored by Paul Ganssle's avatar Paul Ganssle Committed by GitHub

Merge pull request #1416 from pganssle/use_six

Switch over to using six.PY{2,3} when possible
parents b48d4900 6e9ea315
Moved several Python version checks over to using ``six.PY2`` and ``six.PY3``.
...@@ -2,6 +2,8 @@ import os ...@@ -2,6 +2,8 @@ import os
import errno import errno
import sys import sys
from .extern import six
def _makedirs_31(path, exist_ok=False): def _makedirs_31(path, exist_ok=False):
try: try:
...@@ -15,7 +17,7 @@ def _makedirs_31(path, exist_ok=False): ...@@ -15,7 +17,7 @@ def _makedirs_31(path, exist_ok=False):
# and exists_ok considerations are disentangled. # and exists_ok considerations are disentangled.
# See https://github.com/pypa/setuptools/pull/1083#issuecomment-315168663 # See https://github.com/pypa/setuptools/pull/1083#issuecomment-315168663
needs_makedirs = ( needs_makedirs = (
sys.version_info.major == 2 or six.PY2 or
(3, 4) <= sys.version_info < (3, 4, 1) (3, 4) <= sys.version_info < (3, 4, 1)
) )
makedirs = _makedirs_31 if needs_makedirs else os.makedirs makedirs = _makedirs_31 if needs_makedirs else os.makedirs
...@@ -411,7 +411,7 @@ def scan_module(egg_dir, base, name, stubs): ...@@ -411,7 +411,7 @@ def scan_module(egg_dir, base, name, stubs):
return True # Extension module return True # Extension module
pkg = base[len(egg_dir) + 1:].replace(os.sep, '.') pkg = base[len(egg_dir) + 1:].replace(os.sep, '.')
module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0] module = pkg + (pkg and '.' or '') + os.path.splitext(name)[0]
if sys.version_info.major == 2: if six.PY2:
skip = 8 # skip magic & date skip = 8 # skip magic & date
elif sys.version_info < (3, 7): elif sys.version_info < (3, 7):
skip = 12 # skip magic & date & file size skip = 12 # skip magic & date & file size
......
...@@ -48,7 +48,7 @@ class VendorImporter: ...@@ -48,7 +48,7 @@ class VendorImporter:
# on later Python versions to cause relative imports # on later Python versions to cause relative imports
# in the vendor package to resolve the same modules # in the vendor package to resolve the same modules
# as those going through this importer. # as those going through this importer.
if sys.version_info.major >= 3: if sys.version_info >= (3, ):
del sys.modules[extant] del sys.modules[extant]
return mod return mod
except ImportError: except ImportError:
......
...@@ -12,6 +12,8 @@ import sysconfig ...@@ -12,6 +12,8 @@ import sysconfig
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from .extern import six
from . import glibc from . import glibc
_osx_arch_pat = re.compile(r'(.+)_(\d+)_(\d+)_(.+)') _osx_arch_pat = re.compile(r'(.+)_(\d+)_(\d+)_(.+)')
...@@ -97,8 +99,8 @@ def get_abi_tag(): ...@@ -97,8 +99,8 @@ def get_abi_tag():
lambda: sys.maxunicode == 0x10ffff, lambda: sys.maxunicode == 0x10ffff,
expected=4, expected=4,
warn=(impl == 'cp' and warn=(impl == 'cp' and
sys.version_info.major == 2)) \ six.PY2)) \
and sys.version_info.major == 2: and six.PY2:
u = 'u' u = 'u'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
elif soabi and soabi.startswith('cpython-'): elif soabi and soabi.startswith('cpython-'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment