예제 #1
0
def interactive(idx=0, DongleClass=RfCat, intro=''):
    global d
    import rflib.chipcon_nic as rfnic
    import atexit

    d = DongleClass(idx=idx)
    d.setModeRX()       # this puts the dongle into receive mode
    atexit.register(cleanupInteractiveAtExit)

    gbls = globals()
    lcls = locals()

    try:
        import IPython.Shell
        ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
        print intro
        ipsh.mainloop(intro)

    except ImportError, e:
        try:
            from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
            ipsh = TerminalInteractiveShell()
            ipsh.user_global_ns.update(gbls)
            ipsh.user_global_ns.update(lcls)
            ipsh.autocall = 2       # don't require parenthesis around *everything*.  be smart!
            ipsh.mainloop(intro)
        except ImportError, e:
            print e
            shell = code.InteractiveConsole(gbls)
            shell.interact(intro)
예제 #2
0
def interactive(idx=0, DongleClass=RfCat, intro=''):
    global d
    import rflib.chipcon_nic as rfnic
    import atexit

    d = DongleClass(idx=idx)
    d.setModeRX()  # this puts the dongle into receive mode
    atexit.register(cleanupInteractiveAtExit)

    gbls = globals()
    lcls = locals()

    try:
        import IPython.Shell
        ipsh = IPython.Shell.IPShell(argv=[''],
                                     user_ns=lcls,
                                     user_global_ns=gbls)
        print intro
        ipsh.mainloop(intro)

    except ImportError, e:
        try:
            from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
            ipsh = TerminalInteractiveShell()
            ipsh.user_global_ns.update(gbls)
            ipsh.user_global_ns.update(lcls)
            ipsh.autocall = 2  # don't require parenthesis around *everything*.  be smart!
            ipsh.mainloop(intro)
        except ImportError, e:
            print e
            shell = code.InteractiveConsole(gbls)
            shell.interact(intro)
예제 #3
0
파일: shell.py 프로젝트: alefnula/samovar
    def handle(self, *args, **kwargs):
        imported_objects = {
            'config' : self.config,
        }
        try:
            # Try IPython imports
            from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
            from IPython.config.loader import Config

            cfg = Config()
            shell = TerminalInteractiveShell(config=cfg, user_ns=imported_objects)
            shell.mainloop(display_banner='\n  Samovar  \n')
        except:
            import code
            code.InteractiveConsole(locals=imported_objects).interact()
예제 #4
0
파일: shell.py 프로젝트: delicb/samovar
    def handle(self, *args, **kwargs):
        imported_objects = {
            'config': self.config,
        }
        try:
            # Try IPython imports
            from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
            from IPython.config.loader import Config

            cfg = Config()
            shell = TerminalInteractiveShell(config=cfg,
                                             user_ns=imported_objects)
            shell.mainloop(display_banner='\n  Samovar  \n')
        except:
            import code
            code.InteractiveConsole(locals=imported_objects).interact()
예제 #5
0
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)
예제 #6
0
def start_ipython():
    """Start a global IPython shell, which we need for IPython-specific syntax.
    """
    global get_ipython

    # This function should only ever run once!
    if hasattr(start_ipython, 'already_called'):
        return
    start_ipython.already_called = True

    # Store certain global objects that IPython modifies
    _displayhook = sys.displayhook
    _excepthook = sys.excepthook
    _main = sys.modules.get('__main__')

    # Create custom argv and namespaces for our IPython to be test-friendly
    config = tools.default_config()

    # Create and initialize our test-friendly IPython instance.
    shell = TerminalInteractiveShell.instance(config=config,
                                              user_ns=ipnsdict(),
                                              user_global_ns={})

    # A few more tweaks needed for playing nicely with doctests...

    # remove history file
    shell.tempfiles.append(config.HistoryManager.hist_file)

    # These traps are normally only active for interactive use, set them
    # permanently since we'll be mocking interactive sessions.
    shell.builtin_trap.activate()

    # Modify the IPython system call with one that uses getoutput, so that we
    # can capture subcommands and print them to Python's stdout, otherwise the
    # doctest machinery would miss them.
    shell.system = py3compat.MethodType(xsys, shell)

    shell._showtraceback = py3compat.MethodType(_showtraceback, shell)

    # IPython is ready, now clean up some global state...

    # Deactivate the various python system hooks added by ipython for
    # interactive convenience so we don't confuse the doctest system
    sys.modules['__main__'] = _main
    sys.displayhook = _displayhook
    sys.excepthook = _excepthook

    # So that ipython magics and aliases can be doctested (they work by making
    # a call into a global _ip object).  Also make the top-level get_ipython
    # now return this without recursively calling here again.
    _ip = shell
    get_ipython = _ip.get_ipython
    builtin_mod._ip = _ip
    builtin_mod.get_ipython = get_ipython

    # To avoid extra IPython messages during testing, suppress io.stdout/stderr
    io.stdout = StreamProxy('stdout')
    io.stderr = StreamProxy('stderr')

    return _ip
예제 #7
0
def start_ipython():
    """Start a global IPython shell, which we need for IPython-specific syntax.
    """
    global get_ipython

    # This function should only ever run once!
    if hasattr(start_ipython, 'already_called'):
        return
    start_ipython.already_called = True
    
    # Store certain global objects that IPython modifies
    _displayhook = sys.displayhook
    _excepthook = sys.excepthook
    _main = sys.modules.get('__main__')

    # Create custom argv and namespaces for our IPython to be test-friendly
    config = tools.default_config()

    # Create and initialize our test-friendly IPython instance.
    shell = TerminalInteractiveShell.instance(config=config, 
                                              user_ns=ipnsdict(),
                                              user_global_ns={}
                                              )

    # A few more tweaks needed for playing nicely with doctests...
    
    # These traps are normally only active for interactive use, set them
    # permanently since we'll be mocking interactive sessions.
    shell.builtin_trap.activate()

    # Modify the IPython system call with one that uses getoutput, so that we
    # can capture subcommands and print them to Python's stdout, otherwise the
    # doctest machinery would miss them.
    shell.system = MethodType(xsys, shell, TerminalInteractiveShell)
                       

    shell._showtraceback = MethodType(_showtraceback, shell,
                                      TerminalInteractiveShell)

    # IPython is ready, now clean up some global state...
    
    # Deactivate the various python system hooks added by ipython for
    # interactive convenience so we don't confuse the doctest system
    sys.modules['__main__'] = _main
    sys.displayhook = _displayhook
    sys.excepthook = _excepthook

    # So that ipython magics and aliases can be doctested (they work by making
    # a call into a global _ip object).  Also make the top-level get_ipython
    # now return this without recursively calling here again.
    _ip = shell
    get_ipython = _ip.get_ipython
    __builtin__._ip = _ip
    __builtin__.get_ipython = get_ipython
    
    # To avoid extra IPython messages during testing, suppress io.stdout/stderr
    io.stdout = StreamProxy('stdout')
    io.stderr = StreamProxy('stderr')

    return _ip
예제 #8
0
    def construct(self):
        # I am a little hesitant to put these into InteractiveShell itself.
        # But that might be the place for them
        sys.path.insert(0, '')

        # Create an InteractiveShell instance.
        self.shell = TerminalInteractiveShell.instance(config=self.master_config)
예제 #9
0
파일: shell.py 프로젝트: AntoineD/pudb
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)
예제 #10
0
    def construct(self):
        # I am a little hesitant to put these into InteractiveShell itself.
        # But that might be the place for them
        sys.path.insert(0, '')

        # Create an InteractiveShell instance.
        self.shell = TerminalInteractiveShell.instance(config=self.master_config)
예제 #11
0
파일: ipapp.py 프로젝트: fccoelho/ipython
 def init_shell(self):
     """initialize the InteractiveShell instance"""
     # Create an InteractiveShell instance.
     # shell.display_banner should always be False for the terminal
     # based app, because we call shell.show_banner() by hand below
     # so the banner shows *before* all extension loading stuff.
     self.shell = TerminalInteractiveShell.instance(
         config=self.config, display_banner=False, profile_dir=self.profile_dir, ipython_dir=self.ipython_dir
     )
     self.shell.configurables.append(self)
예제 #12
0
 def init_shell(self):
     """initialize the InteractiveShell instance"""
     # Create an InteractiveShell instance.
     # shell.display_banner should always be False for the terminal
     # based app, because we call shell.show_banner() by hand below
     # so the banner shows *before* all extension loading stuff.
     self.shell = TerminalInteractiveShell.instance(config=self.config,
                     display_banner=False, profile_dir=self.profile_dir,
                     ipython_dir=self.ipython_dir)
     self.shell.configurables.append(self)
예제 #13
0
    def init_shell(self):
        """initialize the InteractiveShell instance"""
        # I am a little hesitant to put these into InteractiveShell itself.
        # But that might be the place for them
        sys.path.insert(0, '')

        # Create an InteractiveShell instance.
        # shell.display_banner should always be False for the terminal 
        # based app, because we call shell.show_banner() by hand below
        # so the banner shows *before* all extension loading stuff.
        self.shell = TerminalInteractiveShell.instance(config=self.config,
                        display_banner=False, profile_dir=self.profile_dir,
                        ipython_dir=self.ipython_dir)
예제 #14
0
파일: ipapp.py 프로젝트: sratcliffe/ipython
    def init_shell(self):
        """initialize the InteractiveShell instance"""
        # I am a little hesitant to put these into InteractiveShell itself.
        # But that might be the place for them
        sys.path.insert(0, '')

        # Create an InteractiveShell instance.
        # shell.display_banner should always be False for the terminal
        # based app, because we call shell.show_banner() by hand below
        # so the banner shows *before* all extension loading stuff.
        self.shell = TerminalInteractiveShell.instance(config=self.config,
                        display_banner=False, profile_dir=self.profile_dir,
                        ipython_dir=self.ipython_dir)
예제 #15
0
파일: ipyscript.py 프로젝트: adgaudio/Bin
def execute(file_, verbose = 0, stop_on_error = 1, store_history = 0):
    """ Read and execute lines of code in given open file.
    Supports pure python or ipython-bash style syntax,
    multi-line code, and the IPython feature set
    """
    shell = TerminalInteractiveShell()

    c = shell.get_ipython()
    c.instance() # initialize ipython config

    raw_cells = file_.readlines()
    exception = None

    while raw_cells:
        # Extract smallest possible executable block of code from raw source
        is_completed = c.input_splitter.push(raw_cells.pop(0))
        while not is_completed:
            is_completed = c.input_splitter.push(raw_cells.pop(0))

        cell, raw_cell = c.input_splitter.source_raw_reset()
        # Transform cell into syntactically correct python
        cell = c.prefilter_manager.prefilter_lines(cell) + '\n'

        # If we are storing script in/out history
        if store_history:
            c.history_manager.store_inputs(c.execution_count,
                                              cell, raw_cell)
        # Compile to byte code
        code = compile(cell, 'cellname', 'exec')
        if verbose:
            print '========'
            print 'executing:', cell
            print '========'
        outflag = c.run_code(code)

        if stop_on_error and outflag:
            c.exit()
            break
    def __init__(self, *args, **kwargs):
        # Initialization based on: from IPython.testing.globalipapp import start_ipython

        self._curr_exec_line = 0
        # Store certain global objects that IPython modifies
        _displayhook = sys.displayhook
        _excepthook = sys.excepthook

        # Create and initialize our IPython instance.
        shell = TerminalInteractiveShell.instance()
        # Create an intput splitter to handle input separation
        self.input_splitter = IPythonInputSplitter()

        shell.showtraceback = _showtraceback
        # IPython is ready, now clean up some global state...

        # Deactivate the various python system hooks added by ipython for
        # interactive convenience so we don't confuse the doctest system
        sys.displayhook = _displayhook
        sys.excepthook = _excepthook

        # So that ipython magics and aliases can be doctested (they work by making
        # a call into a global _ip object).  Also make the top-level get_ipython
        # now return this without recursively calling here again.
        get_ipython = shell.get_ipython
        try:
            import __builtin__
        except:
            import builtins as __builtin__
        __builtin__._ip = shell
        __builtin__.get_ipython = get_ipython

        # We want to print to stdout/err as usual.
        io.stdout = original_stdout
        io.stderr = original_stderr

        self.ipython = shell
예제 #17
0
    def __init__(self, *args, **kwargs):        
        # Initialization based on: from IPython.testing.globalipapp import start_ipython
        
        self._curr_exec_line = 0
        # Store certain global objects that IPython modifies
        _displayhook = sys.displayhook
        _excepthook = sys.excepthook
    
        # Create and initialize our IPython instance.
        shell = TerminalInteractiveShell.instance()
        # Create an intput splitter to handle input separation
        self.input_splitter = IPythonInputSplitter()

        shell.showtraceback = _showtraceback
        # IPython is ready, now clean up some global state...
        
        # Deactivate the various python system hooks added by ipython for
        # interactive convenience so we don't confuse the doctest system
        sys.displayhook = _displayhook
        sys.excepthook = _excepthook
    
        # So that ipython magics and aliases can be doctested (they work by making
        # a call into a global _ip object).  Also make the top-level get_ipython
        # now return this without recursively calling here again.
        get_ipython = shell.get_ipython
        try:
            import __builtin__
        except:
            import builtins as __builtin__
        __builtin__._ip = shell
        __builtin__.get_ipython = get_ipython
        
        # We want to print to stdout/err as usual.
        io.stdout = original_stdout
        io.stderr = original_stderr

        self.ipython = shell
예제 #18
0
파일: ipython.py 프로젝트: alonho/pudb
import os

try:
    from IPython import ipapi
except ImportError:
    from IPython.frontend.terminal.interactiveshell import \
            TerminalInteractiveShell
    ip = TerminalInteractiveShell.instance()
    _ipython_version = (0, 11)
else:
    ip = ipapi.get()
    _ipython_version = (0, 10)


def pudb_f_v10(self, arg):
    """ Debug a script (like %run -d) in IPython process, using PuDB.

    This conforms to IPython version 0.10

    Usage:

    %pudb test.py [args]
        Run script test.py under PuDB.
    """

    if not arg.strip():
        print __doc__
        return

    from IPython.genutils import arg_split
    args = arg_split(arg)
예제 #19
0
def autoipython(funcs):
    # Use IPython in combination with AUTO
    # First import the shell class
    ipython11 = False
    try:
        import IPython.Shell
    except ImportError:
        try:  # Check for ipython >= 0.11
            from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
            ipython11 = True
        except ImportError:
            print("Sorry, ipython is not available on this system.")
            return

    if ipython11:
        from IPython.config.loader import Config
        cfg = Config()
        cfg.PromptManager.in_template = "AUTO In [\\#]: "
        cfg.PromptManager.in2_template = "AUTO    .\\D.: "
        cfg.PromptManager.out_template = "Out[\#]: "
        cfg.InteractiveShell.confirm_exit = False
        cfg.InteractiveShell.autocall = 2
        cfg.InteractiveShell.banner2 = """
Welcome to the AUTO IPython CLUI
man     -> List of AUTO CLUI commands"""

        ipshell = TerminalInteractiveShell(config=cfg, user_ns=funcs)
        ipshell.show_banner()
        ipshell.mainloop()
        return

    import IPython
    from IPython.iplib import InteractiveShell

    # 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.

    args = [
        '-pi1', 'AUTO In [\\#]: ', '-pi2', 'AUTO    .\\D.: ', '-po',
        'Out[\#]: ', '-noconfirm_exit', '-autocall', '2'
    ]

    banner = [
        'Python %s\n'
        'Type "copyright", "credits" or "license" '
        'for more information.\n' % (sys.version.split('\n')[0], ),
        "IPython %s -- An enhanced Interactive Python." %
        (IPython.Release.version, ),
        """?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

Welcome to the AUTO IPython CLUI
man     -> List of AUTO CLUI commands"""
    ]

    class AUTOInteractiveShell(AUTOInteractive, InteractiveShell):
        def __init__(self, name, **kw):
            self.parentclass = InteractiveShell
            AUTOInteractive.__init__(self, kw["user_ns"], None)
            InteractiveShell.__init__(self, name, **kw)

        def prefilter(self, line, continue_prompt):
            if not continue_prompt:
                line = self.processShorthand(line)
            line = InteractiveShell.prefilter(self, line, continue_prompt)
            return line

    ipshell = IPython.Shell.IPShell(args,
                                    user_ns=funcs,
                                    user_global_ns=funcs,
                                    shell_class=AUTOInteractiveShell)
    ipshell.IP.user_ns['help'] = ipshell.IP.help
    ipshell.mainloop(banner='\n'.join(banner))
예제 #20
0
try:
    from IPython import ipapi
    ip = ipapi.get()
    _ipython_version = (0, 10)
except ImportError:
    try:
        from IPython.core.magic import register_line_magic
        from IPython import get_ipython
        _ipython_version = (1, 0)
    except ImportError:
        # Note, keep this run last, or else it will raise a deprecation
        # warning.
        from IPython.frontend.terminal.interactiveshell import \
            TerminalInteractiveShell
        ip = TerminalInteractiveShell.instance()
        _ipython_version = (0, 11)


# This conforms to IPython version 0.10
def pudb_f_v10(self, arg):
    """ Debug a script (like %run -d) in the IPython process, using PuDB.

    Usage:

    %pudb test.py [args]
        Run script test.py under PuDB.
    """

    if not arg.strip():
        print(__doc__)
예제 #21
0
def debug():
    from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
    shell = TerminalInteractiveShell(user_ns=vars())
    shell.mainloop()
예제 #22
0
파일: debug.py 프로젝트: drewp/blockstack
def debug():
    from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell

    shell = TerminalInteractiveShell(user_ns=vars())
    shell.mainloop()