def embed(**kwargs): """Call this to embed IPython at the current point in your program. The first invocation of this will create an :class:`InteractiveShellEmbed` instance and then call it. Consecutive calls just call the already created instance. Here is a simple example:: from IPython import embed a = 10 b = 20 embed('First time') c = 30 d = 40 embed Full customization can be done by passing a :class:`Struct` in as the config argument. """ config = kwargs.get('config') header = kwargs.pop('header', u'') if config is None: config = load_default_config() config.InteractiveShellEmbed = config.TerminalInteractiveShell kwargs['config'] = config global _embedded_shell if _embedded_shell is None: _embedded_shell = InteractiveShellEmbed(**kwargs) _embedded_shell(header=header, stack_depth=2)
def embed(**kwargs): """Call this to embed IPython at the current point in your program. The first invocation of this will create an :class:`InteractiveShellEmbed` instance and then call it. Consecutive calls just call the already created instance. Here is a simple example:: from IPython import embed a = 10 b = 20 embed('First time') c = 30 d = 40 embed Full customization can be done by passing a :class:`Struct` in as the config argument. """ config = kwargs.get('config') header = kwargs.pop('header', '') if config is None: config = load_default_config() config.InteractiveShellEmbed = config.TerminalInteractiveShell kwargs['config'] = config global _embedded_shell if _embedded_shell is None: _embedded_shell = InteractiveShellEmbed(**kwargs) _embedded_shell(header=header, stack_depth=2)
def run_ipython_shell_v11(locals, globals, first_time): '''IPython shell from IPython version 0.11''' if first_time: banner = "Hit Ctrl-D to return to PuDB." else: banner = "" from IPython.frontend.terminal.interactiveshell import \ TerminalInteractiveShell from IPython.frontend.terminal.ipapp import load_default_config # XXX: in the future it could be useful to load a 'pudb' config for the # user (if it exists) that could contain the user's macros and other # niceities. config = load_default_config() shell = TerminalInteractiveShell.instance(config=config, banner2=banner) # XXX This avoids a warning about not having unique session/line numbers. # See the HistoryManager.writeout_cache method in IPython.core.history. shell.history_manager.new_session() # Save the originating namespace old_locals = shell.user_ns old_globals = shell.user_global_ns # Update shell with current namespace _update_ns(shell, locals, globals) shell.mainloop(banner) # Restore originating namespace _update_ns(shell, old_locals, old_globals)
def invoke(cls, ns, banner): # pragma: nocover """ :param ns: local namespace :param banner: interactive shell startup banner Embed an interactive ipython shell. Try the InteractiveShellEmbed API first, fall back on IPShellEmbed for older IPython versions. """ try: from IPython.frontend.terminal.embed import ( InteractiveShellEmbed ) # try and load their default profile from IPython.frontend.terminal.ipapp import ( load_default_config ) config = load_default_config() shell = InteractiveShellEmbed(config=config, banner2=banner) shell(local_ns=ns) except ImportError: # Support for the IPython <= 0.10 shell API from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=[]) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=ns, global_ns={})
def I(**kwds): sys.stdin = sys.stdout = open('/dev/tty', mode='r+b') config = kwds.get('config') header = kwds.pop('header', u'') if config is None: config = load_default_config() config.InteractiveShellEmbed = config.TerminalInteractiveShell kwds['config'] = config shell_kwds = {'header': header} shell_kwds.update(default_shell_kwds) shell = InteractiveShellEmbed(**kwds)(**shell_kwds) # the first invocation is one frame deeper due to deferment default_shell_kwds['stack_depth'] = 2 return shell
def handle_noargs(self, **options): imported_objects = get_import_objects() config = None prompt_prefix = get_prompt_prefix() if prompt_prefix: config = load_default_config() config.PromptManager.in_template = ( '(%s) In [\#]: ' % prompt_prefix) if options['kernel']: from IPython import embed_kernel embed_kernel(local_n=imported_objects, config=config) else: embed(user_ns=imported_objects, config=config)
def shell(store, options, jugspace): ''' shell(store, options, jugspace) Implement 'shell' command. Currently depends on Ipython being installed. ''' try: if IPython.version_info[0]>=1: from IPython.terminal.embed import InteractiveShellEmbed else: from IPython.frontend.terminal.embed import InteractiveShellEmbed from IPython.frontend.terminal.ipapp import load_default_config config = load_default_config() ipshell = InteractiveShellEmbed(config=config, display_banner=_ipython_banner) except ImportError: try: # Fallback for older Python: from IPython.Shell import IPShellEmbed ipshell = IPShellEmbed(banner=_ipython_banner) except ImportError: import sys sys.stderr.write(_ipython_not_found_msg) sys.exit(1) def _load_all(): ''' load_all() Loads all task results. ''' load_all(jugspace, local_ns) local_ns = { 'load_all' : _load_all, 'value' : value, } # This is necessary for some versions of Ipython. See: # http://groups.google.com/group/pylons-discuss/browse_thread/thread/312e3ead5967468a try: del jugspace['__builtins__'] except KeyError: pass jugspace.update(local_ns) local_ns['__name__'] = '__jugfile__' ipshell(global_ns=jugspace, local_ns=local_ns)
def shell(store, options, jugspace): ''' shell(store, options, jugspace) Implement 'shell' command. Currently depends on Ipython being installed. ''' try: from IPython.frontend.terminal.embed import InteractiveShellEmbed from IPython.frontend.terminal.ipapp import load_default_config config = load_default_config() ipshell = InteractiveShellEmbed(config=config, display_banner=_ipython_banner) except ImportError: try: # Fallback for older Python: from IPython.Shell import IPShellEmbed ipshell = IPShellEmbed(banner=_ipython_banner) except ImportError: import sys sys.stderr.write(_ipython_not_found_msg) sys.exit(1) def _load_all(): ''' load_all() Loads all task results. ''' load_all(jugspace, local_ns) local_ns = { 'load_all': _load_all, 'value': value, } # This is necessary for some versions of Ipython. See: # http://groups.google.com/group/pylons-discuss/browse_thread/thread/312e3ead5967468a try: del jugspace['__builtins__'] except KeyError: pass jugspace.update(local_ns) local_ns['__name__'] = '__jugfile__' ipshell(global_ns=jugspace, local_ns=local_ns)
def call_actuation_console(self): """ Start an interactive python console with the local variables and names preloaded into the environment """ local_vars = {} for k in self.vars.iterkeys(): local_vars[k[1:]] = self.vars[k] local_vars['api'] = lambda x: get_methods(x) try: from IPython.frontend.terminal.embed import TerminalInteractiveShell from IPython.frontend.terminal.ipapp import load_default_config config = load_default_config() console = TerminalInteractiveShell(config=config, user_ns=local_vars) console.mainloop() except ImportError: console = code.InteractiveConsole(local_vars) console.interact()
def invoke(cls, ns, banner): # pragma: nocover """ :param ns: local namespace :param banner: interactive shell startup banner Embed an interactive ipython shell. Try the InteractiveShellEmbed API first, fall back on IPShellEmbed for older IPython versions. """ try: from IPython.frontend.terminal.embed import (InteractiveShellEmbed) # try and load their default profile from IPython.frontend.terminal.ipapp import (load_default_config) config = load_default_config() shell = InteractiveShellEmbed(config=config, banner2=banner) shell(local_ns=ns) except ImportError: # Support for the IPython <= 0.10 shell API from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=[]) shell.set_banner(shell.IP.BANNER + '\n\n' + banner) shell(local_ns=ns, global_ns={})
"""Main neuropy window""" from __future__ import division __authors__ = ['Martin Spacek'] import os import sys import platform # instantiate an IPython embedded shell which shows up in the terminal on demand # and on every exception in the GUI code: from IPython.frontend.terminal.ipapp import load_default_config from IPython.frontend.terminal.embed import InteractiveShellEmbed config = load_default_config() # automatically call the pdb debugger after every exception, override default config: config.TerminalInteractiveShell.pdb = True ipshell = InteractiveShellEmbed(display_banner=False, config=config) # IPython GUI imports, have to come before Qt imports: from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget from IPython.lib import guisupport from IPython.utils.path import get_ipython_dir from IPython.config.loader import PyFileConfigLoader from PyQt4 import QtCore, QtGui, uic from PyQt4.QtGui import QFont NeuropyUi, NeuropyUiBase = uic.loadUiType('neuropy.ui') from __init__ import __version__ from animal import Animal