Skip to content

Commit 35ba63e

Browse files
committed
Simplify a few version checks and reorder them.
It seems logical to check Python version before modules.
1 parent 93462de commit 35ba63e

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

lib/matplotlib/__init__.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@
153153
year = 2007
154154
}"""
155155

156-
try:
157-
import dateutil
158-
except ImportError:
159-
raise ImportError("matplotlib requires dateutil")
156+
157+
_python27 = (sys.version_info.major == 2 and sys.version_info.minor >= 7)
158+
_python34 = (sys.version_info.major == 3 and sys.version_info.minor >= 4)
159+
if not (_python27 or _python34):
160+
raise ImportError("Matplotlib requires Python 2.7 or 3.4 or later")
160161

161162

162163
def compare_versions(a, b):
@@ -173,39 +174,39 @@ def compare_versions(a, b):
173174
else:
174175
return False
175176

176-
if not compare_versions(six.__version__, '1.3'):
177+
178+
try:
179+
import dateutil
180+
except ImportError:
181+
raise ImportError("Matplotlib requires dateutil")
182+
183+
184+
if not compare_versions(six.__version__, '1.10'):
177185
raise ImportError(
178-
'six 1.3 or later is required; you have %s' % (
179-
six.__version__))
186+
"Matplotlib requires six>=1.10; you have %s" % six.__version__)
187+
180188

181189
try:
182190
import pyparsing
183191
except ImportError:
184-
raise ImportError("matplotlib requires pyparsing")
192+
raise ImportError("Matplotlib requires pyparsing")
185193
else:
186194
if not compare_versions(pyparsing.__version__, '2.0.1'):
187195
raise ImportError(
188-
"matplotlib requires pyparsing >= 2.0.1")
189-
190-
191-
if not hasattr(sys, 'argv'): # for modpython
192-
sys.argv = [str('modpython')]
193-
194-
195-
major, minor1, minor2, s, tmp = sys.version_info
196-
_python27 = (major == 2 and minor1 >= 7)
197-
_python34 = (major == 3 and minor1 >= 4)
198-
199-
if not (_python27 or _python34):
200-
raise ImportError('matplotlib requires Python 2.7 or 3.4 or later')
196+
"Matplotlib requires pyparsing>=2.0.1; you have %s"
197+
% pyparsing.__version__)
201198

202199

203200
if not compare_versions(numpy.__version__, __version__numpy__):
204201
raise ImportError(
205-
'numpy %s or later is required; you have %s' % (
202+
"Matplotlib requires numpy>=%s; you have %s" % (
206203
__version__numpy__, numpy.__version__))
207204

208205

206+
if not hasattr(sys, 'argv'): # for modpython
207+
sys.argv = [str('modpython')]
208+
209+
209210
def _is_writable_dir(p):
210211
"""
211212
p is a string pointing to a putative writable dir -- return True p
@@ -1432,7 +1433,7 @@ def _init_tests():
14321433
if (ft2font.__freetype_version__ != LOCAL_FREETYPE_VERSION or
14331434
ft2font.__freetype_build_type__ != 'local'):
14341435
warnings.warn(
1435-
"matplotlib is not built with the correct FreeType version to run "
1436+
"Matplotlib is not built with the correct FreeType version to run "
14361437
"tests. Set local_freetype=True in setup.cfg and rebuild. "
14371438
"Expect many image comparison failures below. "
14381439
"Expected freetype version {0}. "
@@ -1460,7 +1461,7 @@ def test(verbosity=None, coverage=False, switch_backend_warn=True,
14601461
"""run the matplotlib test suite"""
14611462
_init_tests()
14621463
if not os.path.isdir(os.path.join(os.path.dirname(__file__), 'tests')):
1463-
raise ImportError("matplotlib test data is not installed")
1464+
raise ImportError("Matplotlib test data is not installed")
14641465

14651466
old_backend = get_backend()
14661467
old_recursionlimit = sys.getrecursionlimit()
@@ -1574,8 +1575,8 @@ def foo(ax, *args, **kwargs)
15741575

15751576
def param(func):
15761577
new_sig = None
1577-
python_has_signature = major >= 3 and minor1 >= 3
1578-
python_has_wrapped = major >= 3 and minor1 >= 2
1578+
# signature is since 3.3 and wrapped since 3.2, but we support 3.4+.
1579+
python_has_signature = python_has_wrapped = six.PY3
15791580

15801581
# if in a legacy version of python and IPython is already imported
15811582
# try to use their back-ported signature

0 commit comments

Comments
 (0)