From 4ad311ea66d9ea34f744a11ba783d493a913f8cd 2015-03-25 18:08:42 From: Thomas Kluyver Date: 2015-03-25 18:08:42 Subject: [PATCH] Merge pull request #8147 from minrk/bigsplit-console Big Split: IPython.terminal.console -> jupyter_console --- diff --git a/IPython/terminal/console.py b/IPython/terminal/console.py new file mode 100644 index 0000000..60a217f --- /dev/null +++ b/IPython/terminal/console.py @@ -0,0 +1,20 @@ +""" +Shim to maintain backwards compatibility with old IPython.terminal.console imports. +""" +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +from __future__ import print_function + +import sys +from warnings import warn + +warn("The `IPython.terminal.console` package has been deprecated. " + "You should import from jupyter_console instead.") + +from IPython.utils.shimmodule import ShimModule + +# Unconditionally insert the shim into sys.modules so that further import calls +# trigger the custom attribute access above + +sys.modules['IPython.terminal.console'] = ShimModule('console', mirror='jupyter_console') diff --git a/IPython/utils/shimmodule.py b/IPython/utils/shimmodule.py index 9b91f27..1ce9043 100644 --- a/IPython/utils/shimmodule.py +++ b/IPython/utils/shimmodule.py @@ -3,6 +3,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +import sys import types class ShimModule(types.ModuleType): @@ -10,6 +11,8 @@ class ShimModule(types.ModuleType): def __init__(self, *args, **kwargs): self._mirror = kwargs.pop("mirror") super(ShimModule, self).__init__(*args, **kwargs) + if sys.version_info >= (3,4): + self.__spec__ = __import__(self._mirror).__spec__ def __getattr__(self, key): # Use the equivalent of import_item(name), see below diff --git a/IPython/terminal/console/__init__.py b/jupyter_console/__init__.py similarity index 100% rename from IPython/terminal/console/__init__.py rename to jupyter_console/__init__.py diff --git a/IPython/terminal/console/__main__.py b/jupyter_console/__main__.py similarity index 100% rename from IPython/terminal/console/__main__.py rename to jupyter_console/__main__.py diff --git a/IPython/terminal/console/app.py b/jupyter_console/app.py similarity index 100% rename from IPython/terminal/console/app.py rename to jupyter_console/app.py diff --git a/IPython/terminal/console/completer.py b/jupyter_console/completer.py similarity index 100% rename from IPython/terminal/console/completer.py rename to jupyter_console/completer.py diff --git a/IPython/terminal/console/interactiveshell.py b/jupyter_console/interactiveshell.py similarity index 100% rename from IPython/terminal/console/interactiveshell.py rename to jupyter_console/interactiveshell.py diff --git a/IPython/terminal/console/tests/__init__.py b/jupyter_console/tests/__init__.py similarity index 100% rename from IPython/terminal/console/tests/__init__.py rename to jupyter_console/tests/__init__.py diff --git a/IPython/terminal/console/tests/test_console.py b/jupyter_console/tests/test_console.py similarity index 100% rename from IPython/terminal/console/tests/test_console.py rename to jupyter_console/tests/test_console.py diff --git a/IPython/terminal/console/tests/test_image_handler.py b/jupyter_console/tests/test_image_handler.py similarity index 100% rename from IPython/terminal/console/tests/test_image_handler.py rename to jupyter_console/tests/test_image_handler.py diff --git a/IPython/terminal/console/tests/writetofile.py b/jupyter_console/tests/writetofile.py similarity index 100% rename from IPython/terminal/console/tests/writetofile.py rename to jupyter_console/tests/writetofile.py diff --git a/IPython/terminal/console/zmqhistory.py b/jupyter_console/zmqhistory.py similarity index 100% rename from IPython/terminal/console/zmqhistory.py rename to jupyter_console/zmqhistory.py