diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index d1f87e4..1cb0bc3 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -474,28 +474,16 @@ class InteractiveShell(SingletonConfigurable): self.init_hooks() self.init_events() self.init_pushd_popd_magic() - # self.init_traceback_handlers use to be here, but we moved it below - # because it and init_io have to come after init_readline. self.init_user_ns() self.init_logger() self.init_builtins() # The following was in post_config_initialization self.init_inspector() - # init_readline() must come before init_io(), because init_io uses - # readline related things. - self.init_readline() - # We save this here in case user code replaces raw_input, but it needs - # to be after init_readline(), because PyPy's readline works by replacing - # raw_input. if py3compat.PY3: self.raw_input_original = input else: self.raw_input_original = raw_input - # init_completer must come after init_readline, because it needs to - # know whether readline is present or not system-wide to configure the - # completers, since the completion machinery can now operate - # independently of readline (e.g. over the network) self.init_completer() # TODO: init_io() needs to happen before init_traceback handlers # because the traceback handlers hardcode the stdout/stderr streams. diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 00b650a..c181005 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -1,5 +1,7 @@ # coding: utf-8 """ +Deprecated since IPython 5.0 + Inputhook management for GUI event loop integration. """ @@ -98,7 +100,9 @@ else: class InputHookManager(object): - """Manage PyOS_InputHook for different GUI toolkits. + """DEPRECATED since IPython 5.0 + + Manage PyOS_InputHook for different GUI toolkits. This class installs various hooks under ``PyOSInputHook`` to handle GUI event loop integration. @@ -121,15 +125,25 @@ class InputHookManager(object): self._current_gui = None def get_pyos_inputhook(self): - """Return the current PyOS_InputHook as a ctypes.c_void_p.""" + """DEPRECATED since IPython 5.0 + + Return the current PyOS_InputHook as a ctypes.c_void_p.""" + warn("`get_pyos_inputhook` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) return ctypes.c_void_p.in_dll(ctypes.pythonapi,"PyOS_InputHook") def get_pyos_inputhook_as_func(self): - """Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.""" + """DEPRECATED since IPython 5.0 + + Return the current PyOS_InputHook as a ctypes.PYFUNCYPE.""" + warn("`get_pyos_inputhook_as_func` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) return self.PYFUNC.in_dll(ctypes.pythonapi,"PyOS_InputHook") def set_inputhook(self, callback): - """Set PyOS_InputHook to callback and return the previous one.""" + """DEPRECATED since IPython 5.0 + + Set PyOS_InputHook to callback and return the previous one.""" # On platforms with 'readline' support, it's all too likely to # have a KeyboardInterrupt signal delivered *even before* an # initial ``try:`` clause in the callback can be executed, so @@ -145,7 +159,9 @@ class InputHookManager(object): return original def clear_inputhook(self, app=None): - """Set PyOS_InputHook to NULL and return the previous one. + """DEPRECATED since IPython 5.0 + + Set PyOS_InputHook to NULL and return the previous one. Parameters ---------- @@ -155,6 +171,8 @@ class InputHookManager(object): the actual value of the parameter is ignored. This uniform interface makes it easier to have user-level entry points in the main IPython app like :meth:`enable_gui`.""" + warn("`clear_inputhook` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) pyos_inputhook_ptr = self.get_pyos_inputhook() original = self.get_pyos_inputhook_as_func() pyos_inputhook_ptr.value = ctypes.c_void_p(None).value @@ -163,7 +181,9 @@ class InputHookManager(object): return original def clear_app_refs(self, gui=None): - """Clear IPython's internal reference to an application instance. + """DEPRECATED since IPython 5.0 + + Clear IPython's internal reference to an application instance. Whenever we create an app for a user on qt4 or wx, we hold a reference to the app. This is needed because in some cases bad things @@ -177,13 +197,17 @@ class InputHookManager(object): the app for that toolkit. References are not held for gtk or tk as those toolkits don't have the notion of an app. """ + warn("`clear_app_refs` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) if gui is None: self.apps = {} elif gui in self.apps: del self.apps[gui] def register(self, toolkitname, *aliases): - """Register a class to provide the event loop for a given GUI. + """DEPRECATED since IPython 5.0 + + Register a class to provide the event loop for a given GUI. This is intended to be used as a class decorator. It should be passed the names with which to register this GUI integration. The classes @@ -196,6 +220,8 @@ class InputHookManager(object): def enable(self, app=None): ... """ + warn("`register` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) def decorator(cls): if ctypes is not None: inst = cls(self) @@ -206,11 +232,17 @@ class InputHookManager(object): return decorator def current_gui(self): - """Return a string indicating the currently active GUI or None.""" + """DEPRECATED since IPython 5.0 + + Return a string indicating the currently active GUI or None.""" + warn("`current_gui` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) return self._current_gui def enable_gui(self, gui=None, app=None): - """Switch amongst GUI input hooks by name. + """DEPRECATED since IPython 5.0 + + Switch amongst GUI input hooks by name. This is a higher level method than :meth:`set_inputhook` - it uses the GUI name to look up a registered object which enables the input hook @@ -234,6 +266,8 @@ class InputHookManager(object): PyOS_InputHook wrapper object or the GUI toolkit app created, if there was one. """ + warn("`enable_gui` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) if gui in (None, GUI_NONE): return self.disable_gui() @@ -250,22 +284,28 @@ class InputHookManager(object): app = gui_hook.enable(app) if app is not None: app._in_event_loop = True - self.apps[gui] = app + self.apps[gui] = app return app def disable_gui(self): - """Disable GUI event loop integration. + """DEPRECATED since IPython 5.0 + + Disable GUI event loop integration. If an application was registered, this sets its ``_in_event_loop`` attribute to False. It then calls :meth:`clear_inputhook`. """ + warn("`disable_gui` is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) gui = self._current_gui if gui in self.apps: self.apps[gui]._in_event_loop = False return self.clear_inputhook() class InputHookBase(object): - """Base class for input hooks for specific toolkits. + """DEPRECATED since IPython 5.0 + + Base class for input hooks for specific toolkits. Subclasses should define an :meth:`enable` method with one argument, ``app``, which will either be an instance of the toolkit's application class, or None. @@ -281,14 +321,19 @@ inputhook_manager = InputHookManager() @inputhook_manager.register('osx') class NullInputHook(InputHookBase): - """A null inputhook that doesn't need to do anything""" + """DEPRECATED since IPython 5.0 + + A null inputhook that doesn't need to do anything""" def enable(self, app=None): - pass + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) @inputhook_manager.register('wx') class WxInputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with wxPython. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with wxPython. Parameters ---------- @@ -309,6 +354,8 @@ class WxInputHook(InputHookBase): import wx app = wx.App(redirect=False, clearSigInt=False) """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) import wx wx_version = V(wx.__version__).version @@ -331,10 +378,14 @@ class WxInputHook(InputHookBase): return app def disable(self): - """Disable event loop integration with wxPython. + """DEPRECATED since IPython 5.0 + + Disable event loop integration with wxPython. This restores appnapp on OS X """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) if _use_appnope(): from appnope import nap nap() @@ -342,7 +393,9 @@ class WxInputHook(InputHookBase): @inputhook_manager.register('qt', 'qt4') class Qt4InputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with PyQt4. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with PyQt4. Parameters ---------- @@ -363,6 +416,8 @@ class Qt4InputHook(InputHookBase): from PyQt4 import QtCore app = QtGui.QApplication(sys.argv) """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) from IPython.lib.inputhookqt4 import create_inputhook_qt4 app, inputhook_qt4 = create_inputhook_qt4(self.manager, app) self.manager.set_inputhook(inputhook_qt4) @@ -373,10 +428,14 @@ class Qt4InputHook(InputHookBase): return app def disable_qt4(self): - """Disable event loop integration with PyQt4. + """DEPRECATED since IPython 5.0 + + Disable event loop integration with PyQt4. This restores appnapp on OS X """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) if _use_appnope(): from appnope import nap nap() @@ -385,6 +444,8 @@ class Qt4InputHook(InputHookBase): @inputhook_manager.register('qt5') class Qt5InputHook(Qt4InputHook): def enable(self, app=None): + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) os.environ['QT_API'] = 'pyqt5' return Qt4InputHook.enable(self, app) @@ -392,7 +453,9 @@ class Qt5InputHook(Qt4InputHook): @inputhook_manager.register('gtk') class GtkInputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with PyGTK. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with PyGTK. Parameters ---------- @@ -407,6 +470,8 @@ class GtkInputHook(InputHookBase): the PyGTK to integrate with terminal based applications like IPython. """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) import gtk try: gtk.set_interactive(True) @@ -419,7 +484,9 @@ class GtkInputHook(InputHookBase): @inputhook_manager.register('tk') class TkInputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with Tk. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with Tk. Parameters ---------- @@ -434,6 +501,8 @@ class TkInputHook(InputHookBase): :class:`InputHookManager`, since creating that object automatically sets ``PyOS_InputHook``. """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) if app is None: try: from tkinter import Tk # Py 3 @@ -448,7 +517,9 @@ class TkInputHook(InputHookBase): @inputhook_manager.register('glut') class GlutInputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with GLUT. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with GLUT. Parameters ---------- @@ -471,6 +542,8 @@ class GlutInputHook(InputHookBase): The default screen mode is set to: glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) import OpenGL.GLUT as glut from IPython.lib.inputhookglut import glut_display_mode, \ @@ -498,12 +571,16 @@ class GlutInputHook(InputHookBase): def disable(self): - """Disable event loop integration with glut. + """DEPRECATED since IPython 5.0 + + Disable event loop integration with glut. This sets PyOS_InputHook to NULL and set the display function to a dummy one and set the timer to a dummy timer that will be triggered very far in the future. """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) import OpenGL.GLUT as glut from glut_support import glutMainLoopEvent @@ -514,7 +591,9 @@ class GlutInputHook(InputHookBase): @inputhook_manager.register('pyglet') class PygletInputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with pyglet. + """DEPRECATED since IPython 5.0 + + Enable event loop integration with pyglet. Parameters ---------- @@ -530,6 +609,8 @@ class PygletInputHook(InputHookBase): IPython. """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) from IPython.lib.inputhookpyglet import inputhook_pyglet self.manager.set_inputhook(inputhook_pyglet) return app @@ -538,7 +619,9 @@ class PygletInputHook(InputHookBase): @inputhook_manager.register('gtk3') class Gtk3InputHook(InputHookBase): def enable(self, app=None): - """Enable event loop integration with Gtk3 (gir bindings). + """DEPRECATED since IPython 5.0 + + Enable event loop integration with Gtk3 (gir bindings). Parameters ---------- @@ -553,6 +636,8 @@ class Gtk3InputHook(InputHookBase): the Gtk3 to integrate with terminal based applications like IPython. """ + warn("This function is deprecated since IPython 5.0 and will be removed in future versions.", + DeprecationWarning, stacklevel=2) from IPython.lib.inputhookgtk3 import inputhook_gtk3 self.manager.set_inputhook(inputhook_gtk3) @@ -568,7 +653,7 @@ guis = inputhook_manager.guihooks def _deprecated_disable(): - warn("This function is deprecated: use disable_gui() instead") + warn("This function is deprecated since IPython 4.0 use disable_gui() instead", DeprecationWarning) inputhook_manager.disable_gui() disable_wx = disable_qt4 = disable_gtk = disable_gtk3 = disable_glut = \ disable_pyglet = disable_osx = _deprecated_disable