From 50f9bd9cebe03c67306d87dd7ea5530c8153924b Mon Sep 17 00:00:00 2001 From: MinRK Date: Fri, 23 Sep 2011 15:03:16 -0700 Subject: [PATCH 1/2] update tornado dependency to 2.1 The notebook server will no longer try to launch with 2.0. Test imports and install doc updated to match. --- IPython/testing/iptest.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 3f9dbdee9..9f30056ca 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -111,7 +111,15 @@ if os.name == 'nt': else: have['zmq'] = test_for('zmq', '2.1.4') have['qt'] = test_for('IPython.external.qt') -have['tornado'] = test_for('tornado') + +try: + import tornado + if tornado.version_info < (2,1,0): + raise ImportError +except ImportError: + have['tornado'] = False +else: + have['tornado'] = True #----------------------------------------------------------------------------- # Functions and classes From 56c8403ac01780bbe8601106a141215294ee87ad Mon Sep 17 00:00:00 2001 From: MinRK Date: Fri, 23 Sep 2011 16:57:40 -0700 Subject: [PATCH 2/2] allow more processing in test_for * test_for uses import_item, instead of __import__ * test_for now allows a callback, for processing the result of import_item prior to comparison with min_zmq * callback is only called when min_zmq is defined * callback's default is to just return mod.__version__ * use this to check tornado version, and zmq as a version tuple * fix pexpect check to use external.pexpect --- IPython/testing/iptest.py | 58 +++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 9f30056ca..97b7e5aa1 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -45,6 +45,7 @@ import nose.plugins.builtin from nose.core import TestProgram # Our own imports +from IPython.utils.importstring import import_item from IPython.utils.path import get_ipython_module_path from IPython.utils.process import find_cmd, pycmd2argv from IPython.utils.sysinfo import sys_info @@ -81,18 +82,38 @@ warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch', #----------------------------------------------------------------------------- # Logic for skipping doctests #----------------------------------------------------------------------------- +def extract_version(mod): + return mod.__version__ -def test_for(mod, min_version=None): - """Test to see if mod is importable.""" +def test_for(item, min_version=None, callback=extract_version): + """Test to see if item is importable, and optionally check against a minimum + version. + + If min_version is given, the default behavior is to check against the + `__version__` attribute of the item, but specifying `callback` allows you to + extract the value you are interested in. e.g:: + + In [1]: import sys + + In [2]: from IPython.testing.iptest import test_for + + In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info) + Out[3]: True + + """ try: - __import__(mod) + check = import_item(item) except (ImportError, RuntimeError): - # GTK reports Runtime error if it can't be initialized even if it's + # GTK reports Runtime error if it can't be initialized even if it's # importable. return False else: if min_version: - return sys.modules[mod].__version__ >= min_version + if callback: + # extra processing step to get version to compare + check = callback(check) + + return check >= min_version else: return True @@ -102,24 +123,27 @@ have = {} have['curses'] = test_for('_curses') have['matplotlib'] = test_for('matplotlib') -have['pexpect'] = test_for('pexpect') +have['pexpect'] = test_for('IPython.external.pexpect') have['pymongo'] = test_for('pymongo') have['wx'] = test_for('wx') have['wx.aui'] = test_for('wx.aui') -if os.name == 'nt': - have['zmq'] = test_for('zmq', '2.1.7') -else: - have['zmq'] = test_for('zmq', '2.1.4') have['qt'] = test_for('IPython.external.qt') -try: - import tornado - if tornado.version_info < (2,1,0): - raise ImportError -except ImportError: - have['tornado'] = False +have['tornado'] = test_for('tornado.version_info', (2,1,0), callback=None) + +if os.name == 'nt': + min_zmq = (2,1,7) else: - have['tornado'] = True + min_zmq = (2,1,4) + +def version_tuple(mod): + "turn '2.1.9' into (2,1,9), and '2.1dev' into (2,1,999)" + # turn 'dev' into 999, because Python3 rejects str-int comparisons + vs = mod.__version__.replace('dev', '.999') + tup = tuple([int(v) for v in vs.split('.') ]) + return tup + +have['zmq'] = test_for('zmq', min_zmq, version_tuple) #----------------------------------------------------------------------------- # Functions and classes