aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/monkey.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-09-03 19:57:54 -0400
committerJason R. Coombs <jaraco@jaraco.com>2017-09-03 20:01:45 -0400
commitdcb24ad15465c266a3f258471766fbbe8fc8a42e (patch)
tree13123440610d78e398476a8ce1e8cc3d9f9ec72e /setuptools/monkey.py
parentf14930e66601b462699c44384c482cd966f53b8f (diff)
parent1b192005562d5cf0de30c02154c58fd1dca577c8 (diff)
downloadexternal_python_setuptools-dcb24ad15465c266a3f258471766fbbe8fc8a42e.tar.gz
external_python_setuptools-dcb24ad15465c266a3f258471766fbbe8fc8a42e.tar.bz2
external_python_setuptools-dcb24ad15465c266a3f258471766fbbe8fc8a42e.zip
Merge branch 'master' into drop-py26
Diffstat (limited to 'setuptools/monkey.py')
-rw-r--r--setuptools/monkey.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/setuptools/monkey.py b/setuptools/monkey.py
index 09f208b1..d9eb7d7b 100644
--- a/setuptools/monkey.py
+++ b/setuptools/monkey.py
@@ -8,6 +8,7 @@ import platform
import types
import functools
from importlib import import_module
+import inspect
from setuptools.extern import six
@@ -20,6 +21,20 @@ if you think you need this functionality.
"""
+def _get_mro(cls):
+ """
+ Returns the bases classes for cls sorted by the MRO.
+
+ Works around an issue on Jython where inspect.getmro will not return all
+ base classes if multiple classes share the same name. Instead, this
+ function will return a tuple containing the class itself, and the contents
+ of cls.__bases__. See https://github.com/pypa/setuptools/issues/1024.
+ """
+ if platform.python_implementation() == "Jython":
+ return (cls,) + cls.__bases__
+ return inspect.getmro(cls)
+
+
def get_unpatched(item):
lookup = (
get_unpatched_class if isinstance(item, six.class_types) else
@@ -35,25 +50,23 @@ def get_unpatched_class(cls):
Also ensures that no other distutils extension monkeypatched the distutils
first.
"""
- while cls.__module__.startswith('setuptools'):
- cls, = cls.__bases__
- if not cls.__module__.startswith('distutils'):
+ external_bases = (
+ cls
+ for cls in _get_mro(cls)
+ if not cls.__module__.startswith('setuptools')
+ )
+ base = next(external_bases)
+ if not base.__module__.startswith('distutils'):
msg = "distutils has already been patched by %r" % cls
raise AssertionError(msg)
- return cls
+ return base
def patch_all():
# we can't patch distutils.cmd, alas
distutils.core.Command = setuptools.Command
- has_issue_12885 = (
- sys.version_info < (3, 4, 6)
- or
- (3, 5) < sys.version_info <= (3, 5, 3)
- or
- (3, 6) < sys.version_info
- )
+ has_issue_12885 = sys.version_info <= (3, 5, 3)
if has_issue_12885:
# fix findall bug in distutils (http://bugs.python.org/issue12885)
@@ -67,8 +80,6 @@ def patch_all():
(3, 4) < sys.version_info < (3, 4, 6)
or
(3, 5) < sys.version_info <= (3, 5, 3)
- or
- (3, 6) < sys.version_info
)
if needs_warehouse: