def ipython_ui(self): from IPython.terminal.ipapp import TerminalIPythonApp import automate self.system.namespace.allow_overwrite.extend( ['_', '__', '___', '_i', '_ii', '_iii', 'quit']) self.system.namespace.update({ k: v for k, v in list(automate.__dict__.items()) if k not in self.system.namespace }) term = TerminalIPythonApp(user_ns=self.system.namespace) self.system.namespace['term'] = term term.initialize([]) term.start()
def load_config_for_embed_ipython(profile_name='debug'): """Load the a config file from the default ipython_dir. """ ipython_dir = get_ipython_dir() profile_dir = os.path.join(ipython_dir, f'profile_{profile_name}') app = TerminalIPythonApp() app.config_file_paths.append(profile_dir) app.load_config_file() config = app.config # XXX: setting the profile in config seems to have no effect for InteractiveShellEmbed. # TODO: learn more about IPython internals... # fix history location with a little workaround if 'hist_file' not in config.HistoryAccessor: config.HistoryManager.hist_file = os.path.join(profile_dir, 'history.sqlite') return config
def _get_debugger_cls(): shell = get_ipython() if shell is None: # Not inside IPython # Build a terminal app in order to force ipython to load the # configuration ipapp = TerminalIPythonApp() # Avoid output (banner, prints) ipapp.interact = False ipapp.initialize(["--no-term-title"]) shell = ipapp.shell else: # Running inside IPython # Detect if embed shell or not and display a message if isinstance(shell, InteractiveShellEmbed): sys.stderr.write( "\nYou are currently into an embedded ipython shell,\n" "the configuration will not be loaded.\n\n") # Let IPython decide about which debugger class to use # This is especially important for tools that fiddle with stdout return shell.debugger_cls
def run(self, pipe, no_ipython, no_bpython): if pipe: # User is attempting to pipe in script through stdin. text = sys.stdin.read() exec(text, None, _make_context()) return # Try IPython (with autoreload) try: from IPython.terminal.ipapp import TerminalIPythonApp app = TerminalIPythonApp(user_ns=self.get_context()) config_file = path.join(path.dirname(alchemist.__file__), "ipython_startup.ipy") app.init_shell() app.shell.banner = self.banner app.initialize(argv=["-i", config_file]) app.start() return except ImportError: pass # Fallback to normal cycle. super(Shell, self).run(no_ipython=no_ipython, no_bpython=no_bpython)
here = abspath(dirname(__file__)) options = join(here, 'source', 'config', 'options') generated = join(options, 'config-generated.txt') def write_doc(name, title, app, preamble=None): filename = join(options, name + '.rst') with open(filename, 'w') as f: f.write(title + '\n') f.write(('=' * len(title)) + '\n') f.write('\n') if preamble is not None: f.write(preamble + '\n\n') f.write(app.document_config_options()) if __name__ == '__main__': # Touch this file for the make target with open(generated, 'w'): pass write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp()) write_doc( 'kernel', 'IPython kernel options', IPKernelApp(), preamble=( "These options can be used in :file:`ipython_kernel_config.py`. " "The kernel also respects any options in `ipython_config.py`"), )
from IPython import get_ipython from IPython.core.debugger import BdbQuit_excepthook from IPython.terminal.ipapp import TerminalIPythonApp from IPython.terminal.embed import InteractiveShellEmbed try: import configparser except: import ConfigParser as configparser shell = get_ipython() if shell is None: # Not inside IPython # Build a terminal app in order to force ipython to load the # configuration ipapp = TerminalIPythonApp() # Avoid output (banner, prints) ipapp.interact = False ipapp.initialize(['--no-term-title']) shell = ipapp.shell else: # Running inside IPython # Detect if embed shell or not and display a message if isinstance(shell, InteractiveShellEmbed): sys.stderr.write( "\nYou are currently into an embedded ipython shell,\n" "the configuration will not be loaded.\n\n") # Let IPython decide about which debugger class to use # This is especially important for tools that fiddle with stdout
f.write(('=' * len(title)) + '\n') f.write('\n') if preamble is not None: f.write(preamble + '\n\n') f.write(configdoc) with open('source/config/options/generated', 'a') as f: f.write(filename + '\n') if __name__ == '__main__': # create empty file with open('source/config/options/generated', 'w'): pass write_doc('terminal', 'Terminal IPython options', TerminalIPythonApp().classes) write_doc( 'kernel', 'IPython kernel options', kernel_classes, preamble= "These options can be used in :file:`ipython_notebook_config.py` " "or in :file:`ipython_qtconsole_config.py`") nbclasses = set(NotebookApp().classes) - set(kernel_classes) write_doc('notebook', 'IPython notebook options', nbclasses, preamble="Any of the :doc:`kernel` can also be used.") try: from IPython.qt.console.qtconsoleapp import IPythonQtConsoleApp
trait_aliases = reverse_aliases(app) filename = options / (name + ".rst") text = [title, "=" * len(title), "\n"] if preamble is not None: text.append(preamble + "\n") text.append(app.document_config_options()) text.extend( class_config_rst_doc(c, trait_aliases) for c in app._classes_inc_parents() ) filename.write_text("\n".join(text)) if __name__ == "__main__": # Touch this file for the make target Path(generated).write_text("") write_doc("terminal", "Terminal IPython options", TerminalIPythonApp()) write_doc( "kernel", "IPython kernel options", IPKernelApp(), preamble=( "These options can be used in :file:`ipython_kernel_config.py`. " "The kernel also respects any options in `ipython_config.py`" ), )