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

Skip to content

Commit cfaa981

Browse files
committed
Some py3fication for matplotlib/__init__, setupext.
Matplotlib.nib was used by the old cocoaagg backend (ef8e81e) which has been deleted a while ago.
1 parent b5391ce commit cfaa981

File tree

2 files changed

+34
-80
lines changed

2 files changed

+34
-80
lines changed

lib/matplotlib/__init__.py

Lines changed: 30 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
import functools
126126
import io
127127
import inspect
128+
from inspect import Parameter
128129
import itertools
129130
import locale
130131
import logging
@@ -174,23 +175,17 @@
174175
}"""
175176

176177

177-
_python27 = (sys.version_info.major == 2 and sys.version_info.minor >= 7)
178-
_python34 = (sys.version_info.major == 3 and sys.version_info.minor >= 4)
179-
if not (_python27 or _python34):
180-
raise ImportError("Matplotlib requires Python 2.7 or 3.4 or later")
181-
182-
if _python27:
183-
_log.addHandler(logging.NullHandler())
184-
185-
186178
def compare_versions(a, b):
187179
"return True if a is greater than or equal to b"
180+
if isinstance(a, bytes):
181+
cbook.warn_deprecated(
182+
"3.0", "compare_version arguments should be strs.")
183+
a = a.decode('ascii')
184+
if isinstance(b, bytes):
185+
cbook.warn_deprecated(
186+
"3.0", "compare_version arguments should be strs.")
187+
b = b.decode('ascii')
188188
if a:
189-
if six.PY3:
190-
if isinstance(a, bytes):
191-
a = a.decode('ascii')
192-
if isinstance(b, bytes):
193-
b = b.decode('ascii')
194189
a = distutils.version.LooseVersion(a)
195190
b = distutils.version.LooseVersion(b)
196191
return a >= b
@@ -750,10 +745,6 @@ def get_py2exe_datafiles():
750745
_, tail = os.path.split(datapath)
751746
d = {}
752747
for root, _, files in os.walk(datapath):
753-
# Need to explicitly remove cocoa_agg files or py2exe complains
754-
# NOTE I don't know why, but do as previous version
755-
if 'Matplotlib.nib' in files:
756-
files.remove('Matplotlib.nib')
757748
files = [os.path.join(root, filename) for filename in files]
758749
root = root.replace(tail, 'mpl-data')
759750
root = root[root.index('mpl-data'):]
@@ -1602,52 +1593,24 @@ def foo(ax, *args, **kwargs)
16021593
replace_names = set(replace_names)
16031594

16041595
def param(func):
1605-
new_sig = None
1606-
# signature is since 3.3 and wrapped since 3.2, but we support 3.4+.
1607-
python_has_signature = python_has_wrapped = six.PY3
1608-
1609-
# if in a legacy version of python and IPython is already imported
1610-
# try to use their back-ported signature
1611-
if not python_has_signature and 'IPython' in sys.modules:
1612-
try:
1613-
import IPython.utils.signatures
1614-
signature = IPython.utils.signatures.signature
1615-
Parameter = IPython.utils.signatures.Parameter
1616-
except ImportError:
1617-
pass
1596+
sig = inspect.signature(func)
1597+
_has_varargs = False
1598+
_has_varkwargs = False
1599+
_arg_names = []
1600+
params = list(sig.parameters.values())
1601+
for p in params:
1602+
if p.kind is Parameter.VAR_POSITIONAL:
1603+
_has_varargs = True
1604+
elif p.kind is Parameter.VAR_KEYWORD:
1605+
_has_varkwargs = True
16181606
else:
1619-
python_has_signature = True
1620-
else:
1621-
if python_has_signature:
1622-
signature = inspect.signature
1623-
Parameter = inspect.Parameter
1624-
1625-
if not python_has_signature:
1626-
arg_spec = inspect.getargspec(func)
1627-
_arg_names = arg_spec.args
1628-
_has_varargs = arg_spec.varargs is not None
1629-
_has_varkwargs = arg_spec.keywords is not None
1607+
_arg_names.append(p.name)
1608+
data_param = Parameter('data', Parameter.KEYWORD_ONLY, default=None)
1609+
if _has_varkwargs:
1610+
params.insert(-1, data_param)
16301611
else:
1631-
sig = signature(func)
1632-
_has_varargs = False
1633-
_has_varkwargs = False
1634-
_arg_names = []
1635-
params = list(sig.parameters.values())
1636-
for p in params:
1637-
if p.kind is Parameter.VAR_POSITIONAL:
1638-
_has_varargs = True
1639-
elif p.kind is Parameter.VAR_KEYWORD:
1640-
_has_varkwargs = True
1641-
else:
1642-
_arg_names.append(p.name)
1643-
data_param = Parameter('data',
1644-
Parameter.KEYWORD_ONLY,
1645-
default=None)
1646-
if _has_varkwargs:
1647-
params.insert(-1, data_param)
1648-
else:
1649-
params.append(data_param)
1650-
new_sig = sig.replace(parameters=params)
1612+
params.append(data_param)
1613+
new_sig = sig.replace(parameters=params)
16511614
# Import-time check: do we have enough information to replace *args?
16521615
arg_names_at_runtime = False
16531616
# there can't be any positional arguments behind *args and no
@@ -1701,7 +1664,7 @@ def param(func):
17011664
label_namer_pos = 9999 # bigger than all "possible" argument lists
17021665
if (label_namer and # we actually want a label here ...
17031666
arg_names and # and we can determine a label in *args ...
1704-
(label_namer in arg_names)): # and it is in *args
1667+
label_namer in arg_names): # and it is in *args
17051668
label_namer_pos = arg_names.index(label_namer)
17061669
if "label" in arg_names:
17071670
label_pos = arg_names.index("label")
@@ -1789,10 +1752,10 @@ def inner(ax, *args, **kwargs):
17891752
# didn't set one. Note: if the user puts in "label=None", it does
17901753
# *NOT* get replaced!
17911754
user_supplied_label = (
1792-
(len(args) >= _label_pos) or # label is included in args
1793-
('label' in kwargs) # ... or in kwargs
1755+
len(args) >= _label_pos or # label is included in args
1756+
'label' in kwargs # ... or in kwargs
17941757
)
1795-
if (label_namer and not user_supplied_label):
1758+
if label_namer and not user_supplied_label:
17961759
if _label_namer_pos < len(args):
17971760
kwargs['label'] = get_label(args[_label_namer_pos], label)
17981761
elif label_namer in kwargs:
@@ -1808,10 +1771,7 @@ def inner(ax, *args, **kwargs):
18081771

18091772
inner.__doc__ = _add_data_doc(inner.__doc__,
18101773
replace_names, replace_all_args)
1811-
if not python_has_wrapped:
1812-
inner.__wrapped__ = func
1813-
if new_sig is not None:
1814-
inner.__signature__ = new_sig
1774+
inner.__signature__ = new_sig
18151775
return inner
18161776

18171777
return param

setupext.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,9 @@ def get_include_dirs():
188188

189189
def is_min_version(found, minversion):
190190
"""
191-
Returns `True` if `found` is at least as high a version as
192-
`minversion`.
191+
Returns whether *found* is a version at least as high as *minversion*.
193192
"""
194-
expected_version = version.LooseVersion(minversion)
195-
found_version = version.LooseVersion(found)
196-
return found_version >= expected_version
193+
return version.LooseVersion(found) >= version.LooseVersion(minversion)
197194

198195

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

13671364
def get_install_requires(self):
1368-
install_requires = [
1365+
return [
13691366
"cycler>=0.10",
1367+
"kiwisolver>=1.0.1",
13701368
"pyparsing>=2.0.1,!=2.0.4,!=2.1.2,!=2.1.6",
13711369
"python-dateutil>=2.1",
13721370
"pytz",
13731371
"six>=1.10",
1374-
"kiwisolver>=1.0.1",
13751372
]
1376-
if sys.version_info < (3,) and os.name == "posix":
1377-
install_requires += ["subprocess32"]
1378-
return install_requires
13791373

13801374

13811375
class BackendAgg(OptionalBackendPackage):

0 commit comments

Comments
 (0)