Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Some py3fication for matplotlib/__init__, setupext. #10652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 30 additions & 70 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
import functools
import io
import inspect
from inspect import Parameter
import itertools
import locale
import logging
Expand Down Expand Up @@ -174,23 +175,17 @@
}"""


_python27 = (sys.version_info.major == 2 and sys.version_info.minor >= 7)
_python34 = (sys.version_info.major == 3 and sys.version_info.minor >= 4)
if not (_python27 or _python34):
raise ImportError("Matplotlib requires Python 2.7 or 3.4 or later")

if _python27:
_log.addHandler(logging.NullHandler())


def compare_versions(a, b):
"return True if a is greater than or equal to b"
if isinstance(a, bytes):
cbook.warn_deprecated(
"3.0", "compare_version arguments should be strs.")
a = a.decode('ascii')
if isinstance(b, bytes):
cbook.warn_deprecated(
"3.0", "compare_version arguments should be strs.")
b = b.decode('ascii')
if a:
if six.PY3:
if isinstance(a, bytes):
a = a.decode('ascii')
if isinstance(b, bytes):
b = b.decode('ascii')
a = distutils.version.LooseVersion(a)
b = distutils.version.LooseVersion(b)
return a >= b
Expand Down Expand Up @@ -750,10 +745,6 @@ def get_py2exe_datafiles():
_, tail = os.path.split(datapath)
d = {}
for root, _, files in os.walk(datapath):
# Need to explicitly remove cocoa_agg files or py2exe complains
# NOTE I don't know why, but do as previous version
if 'Matplotlib.nib' in files:
files.remove('Matplotlib.nib')
files = [os.path.join(root, filename) for filename in files]
root = root.replace(tail, 'mpl-data')
root = root[root.index('mpl-data'):]
Expand Down Expand Up @@ -1602,52 +1593,24 @@ def foo(ax, *args, **kwargs)
replace_names = set(replace_names)

def param(func):
new_sig = None
# signature is since 3.3 and wrapped since 3.2, but we support 3.4+.
python_has_signature = python_has_wrapped = six.PY3

# if in a legacy version of python and IPython is already imported
# try to use their back-ported signature
if not python_has_signature and 'IPython' in sys.modules:
try:
import IPython.utils.signatures
signature = IPython.utils.signatures.signature
Parameter = IPython.utils.signatures.Parameter
except ImportError:
pass
sig = inspect.signature(func)
_has_varargs = False
_has_varkwargs = False
_arg_names = []
params = list(sig.parameters.values())
for p in params:
if p.kind is Parameter.VAR_POSITIONAL:
_has_varargs = True
elif p.kind is Parameter.VAR_KEYWORD:
_has_varkwargs = True
else:
python_has_signature = True
else:
if python_has_signature:
signature = inspect.signature
Parameter = inspect.Parameter

if not python_has_signature:
arg_spec = inspect.getargspec(func)
_arg_names = arg_spec.args
_has_varargs = arg_spec.varargs is not None
_has_varkwargs = arg_spec.keywords is not None
_arg_names.append(p.name)
data_param = Parameter('data', Parameter.KEYWORD_ONLY, default=None)
if _has_varkwargs:
params.insert(-1, data_param)
else:
sig = signature(func)
_has_varargs = False
_has_varkwargs = False
_arg_names = []
params = list(sig.parameters.values())
for p in params:
if p.kind is Parameter.VAR_POSITIONAL:
_has_varargs = True
elif p.kind is Parameter.VAR_KEYWORD:
_has_varkwargs = True
else:
_arg_names.append(p.name)
data_param = Parameter('data',
Parameter.KEYWORD_ONLY,
default=None)
if _has_varkwargs:
params.insert(-1, data_param)
else:
params.append(data_param)
new_sig = sig.replace(parameters=params)
params.append(data_param)
new_sig = sig.replace(parameters=params)
# Import-time check: do we have enough information to replace *args?
arg_names_at_runtime = False
# there can't be any positional arguments behind *args and no
Expand Down Expand Up @@ -1701,7 +1664,7 @@ def param(func):
label_namer_pos = 9999 # bigger than all "possible" argument lists
if (label_namer and # we actually want a label here ...
arg_names and # and we can determine a label in *args ...
(label_namer in arg_names)): # and it is in *args
label_namer in arg_names): # and it is in *args
label_namer_pos = arg_names.index(label_namer)
if "label" in arg_names:
label_pos = arg_names.index("label")
Expand Down Expand Up @@ -1789,10 +1752,10 @@ def inner(ax, *args, **kwargs):
# didn't set one. Note: if the user puts in "label=None", it does
# *NOT* get replaced!
user_supplied_label = (
(len(args) >= _label_pos) or # label is included in args
('label' in kwargs) # ... or in kwargs
len(args) >= _label_pos or # label is included in args
'label' in kwargs # ... or in kwargs
)
if (label_namer and not user_supplied_label):
if label_namer and not user_supplied_label:
if _label_namer_pos < len(args):
kwargs['label'] = get_label(args[_label_namer_pos], label)
elif label_namer in kwargs:
Expand All @@ -1808,10 +1771,7 @@ def inner(ax, *args, **kwargs):

inner.__doc__ = _add_data_doc(inner.__doc__,
replace_names, replace_all_args)
if not python_has_wrapped:
inner.__wrapped__ = func
if new_sig is not None:
inner.__signature__ = new_sig
inner.__signature__ = new_sig
return inner

return param
Expand Down
14 changes: 4 additions & 10 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,9 @@ def get_include_dirs():

def is_min_version(found, minversion):
"""
Returns `True` if `found` is at least as high a version as
`minversion`.
Returns whether *found* is a version at least as high as *minversion*.
"""
expected_version = version.LooseVersion(minversion)
found_version = version.LooseVersion(found)
return found_version >= expected_version
return version.LooseVersion(found) >= version.LooseVersion(minversion)


# Define the display functions only if display_status is True.
Expand Down Expand Up @@ -1365,17 +1362,14 @@ def check(self):
return "handled by setuptools"

def get_install_requires(self):
install_requires = [
return [
"cycler>=0.10",
"kiwisolver>=1.0.1",
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
"python-dateutil>=2.1",
"pytz",
"six>=1.10",
"kiwisolver>=1.0.1",
]
if sys.version_info < (3,) and os.name == "posix":
install_requires += ["subprocess32"]
return install_requires


class BackendAgg(OptionalBackendPackage):
Expand Down