Last active
December 30, 2015 01:59
-
-
Save lukecampbell/7759688 to your computer and use it in GitHub Desktop.
breakpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def breakpoint(scope=None, global_scope=None): | |
import traceback | |
from IPython.config.loader import Config | |
ipy_config = Config() | |
ipy_config.PromptManager.in_template = '><> ' | |
ipy_config.PromptManager.in2_template = '... ' | |
ipy_config.PromptManager.out_template = '--> ' | |
ipy_config.InteractiveShellEmbed.confirm_exit = False | |
# First import the embeddable shell class | |
from IPython.frontend.terminal.embed import InteractiveShellEmbed | |
from mock import patch | |
if scope is not None: | |
locals().update(scope) | |
if global_scope is not None: | |
globals().update(global_scope) | |
# Update namespace of interactive shell | |
# TODO: Cleanup namespace even further | |
# Now create an instance of the embeddable shell. The first argument is a | |
# string with options exactly as you would type them if you were starting | |
# IPython at the system command line. Any parameters you want to define for | |
# configuration can thus be specified here. | |
with patch("IPython.core.interactiveshell.InteractiveShell.init_virtualenv"): | |
ipshell = InteractiveShellEmbed(config=ipy_config, | |
banner1="Entering Breakpoint Shell", | |
exit_msg = 'Returning...') | |
stack = traceback.extract_stack(limit=2) | |
message = 'File %s, line %s, in %s' % stack[0][:-1] | |
try: | |
import growl | |
growl.growl('breakpoint', 'Ready') | |
except: | |
pass | |
ipshell('(%s) Breakpoint @ %s' % ('breakpoint', message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment