##// END OF EJS Templates
Backport PR #9965: Allow the debugger to work in code which calls __import__("__main__")...
Backport PR #9965: Allow the debugger to work in code which calls __import__("__main__") this basically resolves 9941 as suggested by takluyver in https://github.com/ipython/ipython/issues/9941 issuecomment-248071079. In summary, it is needed to run e.g. standard unittests within the debugger. For more details see 9941. Signed-off-by: Thomas Kluyver <thomas@kluyver.me.uk>

File last commit:

r22613:b7f74ca8
r23137:44edfbe8
Show More
__init__.py
48 lines | 1.0 KiB | text/x-python | PythonLexer
import importlib
import os
aliases = {
'qt4': 'qt',
'gtk2': 'gtk',
}
backends = [
'qt', 'qt4', 'qt5',
'gtk', 'gtk2', 'gtk3',
'tk',
'wx',
'pyglet', 'glut',
'osx',
]
registered = {}
def register(name, inputhook):
"""Register the function *inputhook* as an event loop integration."""
registered[name] = inputhook
class UnknownBackend(KeyError):
def __init__(self, name):
self.name = name
def __str__(self):
return ("No event loop integration for {!r}. "
"Supported event loops are: {}").format(self.name,
', '.join(backends + sorted(registered)))
def get_inputhook_func(gui):
if gui in registered:
return registered[gui]
if gui not in backends:
raise UnknownBackend(gui)
if gui in aliases:
return get_inputhook_func(aliases[gui])
if gui == 'qt5':
os.environ['QT_API'] = 'pyqt5'
gui = 'qt'
mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui)
return mod.inputhook