Repository: nipy/nipype

Issue:
Shim warning when using IPython >= 4.0.0
One of our C-PAC users came across the following deprecation warning during their pipeline run:

> /clusterdata/apps/anaconda/lib/python2.7/site-packages/IPython/kernel/**init**.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
> 
>   "You should import from ipykernel or jupyter_client instead.", ShimWarning)
> 
> /clusterdata/apps/anaconda/lib/python2.7/site-packages/IPython/parallel.py:13: ShimWarning: The `IPython.parallel` package has been deprecated. You should import from ipyparallel instead.
> 
>   "You should import from ipyparallel instead.", ShimWarning)

I was able to determine  that this is because, starting in IPython 4.0.0, the IPython developers have chosen to separate IPython.parallel and IPython.kernel into separate packages.  Is there some way that nipype could take this into account by determining if the IPython version number is >= 4.0.0, stopping execution if so (and the packages are not installed), and warning users to download these two packages (or some other appropriate behavior)?  If the packages are installed, the new import statements could be used instead.

Shim warning when using IPython >= 4.0.0
One of our C-PAC users came across the following deprecation warning during their pipeline run:

> /clusterdata/apps/anaconda/lib/python2.7/site-packages/IPython/kernel/**init**.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
> 
>   "You should import from ipykernel or jupyter_client instead.", ShimWarning)
> 
> /clusterdata/apps/anaconda/lib/python2.7/site-packages/IPython/parallel.py:13: ShimWarning: The `IPython.parallel` package has been deprecated. You should import from ipyparallel instead.
> 
>   "You should import from ipyparallel instead.", ShimWarning)

I was able to determine  that this is because, starting in IPython 4.0.0, the IPython developers have chosen to separate IPython.parallel and IPython.kernel into separate packages.  Is there some way that nipype could take this into account by determining if the IPython version number is >= 4.0.0, stopping execution if so (and the packages are not installed), and warning users to download these two packages (or some other appropriate behavior)?  If the packages are installed, the new import statements could be used instead.



Discussion:
I too am getting this warning:

12:36 $ git grep IPython.kernel
nipype/pipeline/plugins/ipythonx.py:    from IPython.kernel.contexts import ConnectionRefusedError
nipype/pipeline/plugins/ipythonx.py:            name = 'IPython.kernel.client'
✔ /Shared/pinc/sharedopt/20160202/RHEL6/NEP-11/NIPYPE [master|✚ 1] 
12:36 $ ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead

I too am getting this warning:

12:36 $ git grep IPython.kernel
nipype/pipeline/plugins/ipythonx.py:    from IPython.kernel.contexts import ConnectionRefusedError
nipype/pipeline/plugins/ipythonx.py:            name = 'IPython.kernel.client'
✔ /Shared/pinc/sharedopt/20160202/RHEL6/NEP-11/NIPYPE [master|✚ 1] 
12:36 $ ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead


Resolving patch:
diff --git a/nipype/pipeline/plugins/ipython.py b/nipype/pipeline/plugins/ipython.py
--- a/nipype/pipeline/plugins/ipython.py
+++ b/nipype/pipeline/plugins/ipython.py
@@ -5,7 +5,6 @@
 
 from future import standard_library
 standard_library.install_aliases()
-
 from pickle import dumps
 
 import sys
@@ -47,7 +46,7 @@ class IPythonPlugin(DistributedPluginBase):
 
     def __init__(self, plugin_args=None):
         if IPython_not_loaded:
-            raise ImportError('ipyparallel could not be imported')
+            raise ImportError('Please install ipyparallel to use this plugin.')
         super(IPythonPlugin, self).__init__(plugin_args=plugin_args)
         self.iparallel = None
         self.taskclient = None
@@ -64,7 +63,7 @@ def run(self, graph, config, updatehash=False):
             __import__(name)
             self.iparallel = sys.modules[name]
         except ImportError:
-            raise ImportError("Ipython kernel not found. Parallel execution "
+            raise ImportError("ipyparallel not found. Parallel execution "
                               "will be unavailable")
         try:
             self.taskclient = self.iparallel.Client()
diff --git a/nipype/pipeline/plugins/ipythonx.py b/nipype/pipeline/plugins/ipythonx.py
--- a/nipype/pipeline/plugins/ipythonx.py
+++ b/nipype/pipeline/plugins/ipythonx.py
@@ -5,11 +5,13 @@
 
 import sys
 
+from ...interfaces.base import LooseVersion
 IPython_not_loaded = False
 try:
     from IPython import __version__ as IPyversion
-    from IPython.kernel.contexts import ConnectionRefusedError
-except:
+    if LooseVersion(IPyversion) < LooseVersion('0.11'):
+        from IPython.kernel.contexts import ConnectionRefusedError
+except ImportError:
     IPython_not_loaded = True
 
 
@@ -21,6 +23,12 @@ class IPythonXPlugin(DistributedPluginBase):
     """
 
     def __init__(self, plugin_args=None):
+        if LooseVersion(IPyversion) > LooseVersion('0.10.1'):
+            raise EnvironmentError(('The IPythonX plugin can only be used with'
+                                    ' older IPython versions. Please use the '
+                                    'IPython plugin instead.'
+                                    ))
+        DeprecationWarning('This plugin will be deprecated as of version 0.13')
         if IPython_not_loaded:
             raise ImportError('ipyparallel could not be imported')
         super(IPythonXPlugin, self).__init__(plugin_args=plugin_args)


Test patch: