def __init__(self, shell=None): """ Initialize the Sage plugin. """ self.shell = shell self.auto_magics = SageMagics(shell) self.shell.register_magics(self.auto_magics) import sage.repl.display.formatter as formatter self.shell.display_formatter.formatters['text/plain'] = ( formatter.SagePlainTextFormatter(config=shell.config)) import sage.misc.edit_module as edit_module self.shell.set_hook('editor', edit_module.edit_devel) self.init_inspector() self.init_line_transforms() import inputhook inputhook.install() import sage.all # until sage's import hell is fixed self.shell.verbose_quit = True self.set_quit_hook() self.register_interface_magics() if SAGE_IMPORTALL == 'yes': self.init_environment()
def get_test_shell(): """ Returns a IPython shell that can be used in testing the functions in this module. :returns: an IPython shell EXAMPLES:: sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell(); shell <sage.repl.interpreter.SageTerminalInteractiveShell object at 0x...> TESTS: Check that :trac:`14070` has been resolved:: sage: from sage.tests.cmdline import test_executable sage: cmd = 'from sage.repl.interpreter import get_test_shell; shell = get_test_shell()' sage: (out, err, ret) = test_executable(["sage", "-c", cmd]) sage: out + err '' """ app = SageTerminalApp.instance(config=copy.deepcopy(DEFAULT_SAGE_CONFIG)) if app.shell is None: app.initialize(argv=[]) # overwrite the default (console + graphics) formatter with the plain text one import sage.repl.display.formatter as formatter app.shell.display_formatter.formatters['text/plain'] = ( formatter.SagePlainTextFormatter(config=app.shell.config)) # No quit noise app.shell.verbose_quit = False return app.shell
def get_test_shell(): """ Returns a IPython shell that can be used in testing the functions in this module. OUTPUT: An IPython shell EXAMPLES:: sage: from sage.repl.interpreter import get_test_shell sage: shell = get_test_shell(); shell <sage.repl.interpreter.SageTestShell object at 0x...> sage: shell.parent.shell_class <class 'sage.repl.interpreter.SageTestShell'> sage: shell.parent.test_shell True sage: shell.quit() TESTS: Check that :trac:`14070` has been resolved:: sage: from sage.tests.cmdline import test_executable sage: cmd = 'from sage.repl.interpreter import get_test_shell; shell = get_test_shell()' sage: (out, err, ret) = test_executable(["sage", "-c", cmd]) sage: out + err '' """ config = copy.deepcopy(DEFAULT_SAGE_CONFIG) config.TerminalIPythonApp.test_shell = True config.TerminalIPythonApp.shell_class = SageTestShell app = SageTerminalApp.instance(config=config) if app.shell is None: app.initialize(argv=[]) else: try: app.shell._restart() except AttributeError: pass # overwrite the default (console + graphics) formatter with the plain text one import sage.repl.display.formatter as formatter app.shell.display_formatter.formatters['text/plain'] = ( formatter.SagePlainTextFormatter(config=app.shell.config)) # No quit noise app.shell.verbose_quit = False return app.shell