From 05331d1aecacf5bc72cbd5747791db9e08253bde 2016-06-30 22:18:18 From: Matthias Bussonnier Date: 2016-06-30 22:18:18 Subject: [PATCH] remove rest of readline, pass II --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 7b686f9..5a69341 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -62,7 +62,6 @@ from IPython.utils import PyColorize from IPython.utils import io from IPython.utils import py3compat from IPython.utils import openpy -from IPython.utils.contexts import NoOpContext from IPython.utils.decorators import undoc from IPython.utils.io import ask_yes_no from IPython.utils.ipstruct import Struct @@ -574,9 +573,6 @@ class InteractiveShell(SingletonConfigurable): self.tempfiles = [] self.tempdirs = [] - # Keep track of readline usage (later set by init_readline) - self.has_readline = False - # keep track of where we started running (mainly for crash post-mortem) # This is not being used anywhere currently. self.starting_dir = py3compat.getcwd() @@ -659,11 +655,8 @@ class InteractiveShell(SingletonConfigurable): # override sys.stdout and sys.stderr themselves, you need to do that # *before* instantiating this class, because io holds onto # references to the underlying streams. - if (sys.platform == 'win32' or sys.platform == 'cli') and self.has_readline: - io.stdout = io.stderr = io.IOStream(self.readline._outputfile) - else: - io.stdout = io.IOStream(sys.stdout) - io.stderr = io.IOStream(sys.stderr) + io.stdout = io.IOStream(sys.stdout) + io.stderr = io.IOStream(sys.stderr) def init_prompts(self): # Set system prompts, so that scripts can decide if they are running @@ -984,9 +977,7 @@ class InteractiveShell(SingletonConfigurable): error('No traceback has been produced, nothing to debug.') return - - with self.readline_no_record: - self.InteractiveTB.debugger(force=True) + self.InteractiveTB.debugger(force=True) #------------------------------------------------------------------------- # Things related to IPython's various namespaces @@ -1889,10 +1880,7 @@ class InteractiveShell(SingletonConfigurable): def init_readline(self): """Moved to terminal subclass, here only to simplify the init logic.""" - self.readline = None # Set a number of methods that depend on readline to be no-op - self.readline_no_record = NoOpContext() - self.set_readline_completer = no_op self.set_custom_completer = no_op @skip_doctest @@ -1929,7 +1917,7 @@ class InteractiveShell(SingletonConfigurable): self.Completer = IPCompleter(shell=self, namespace=self.user_ns, global_namespace=self.user_global_ns, - use_readline=self.has_readline, + use_readline=False, parent=self, ) self.configurables.append(self.Completer) diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 6ab3d24..6c3ad73 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -705,55 +705,54 @@ python-profiler package from non-free.""") try: stats = None - with self.shell.readline_no_record: - if 'p' in opts: - stats = self._run_with_profiler(code, opts, code_ns) + if 'p' in opts: + stats = self._run_with_profiler(code, opts, code_ns) + else: + if 'd' in opts: + bp_file, bp_line = parse_breakpoint( + opts.get('b', ['1'])[0], filename) + self._run_with_debugger( + code, code_ns, filename, bp_line, bp_file) else: - if 'd' in opts: - bp_file, bp_line = parse_breakpoint( - opts.get('b', ['1'])[0], filename) - self._run_with_debugger( - code, code_ns, filename, bp_line, bp_file) + if 'm' in opts: + def run(): + self.shell.safe_run_module(modulename, prog_ns) else: - if 'm' in opts: - def run(): - self.shell.safe_run_module(modulename, prog_ns) - else: - if runner is None: - runner = self.default_runner - if runner is None: - runner = self.shell.safe_execfile - - def run(): - runner(filename, prog_ns, prog_ns, - exit_ignore=exit_ignore) - - if 't' in opts: - # timed execution - try: - nruns = int(opts['N'][0]) - if nruns < 1: - error('Number of runs must be >=1') - return - except (KeyError): - nruns = 1 - self._run_with_timing(run, nruns) - else: - # regular execution - run() - - if 'i' in opts: - self.shell.user_ns['__name__'] = __name__save - else: - # update IPython interactive namespace + if runner is None: + runner = self.default_runner + if runner is None: + runner = self.shell.safe_execfile + + def run(): + runner(filename, prog_ns, prog_ns, + exit_ignore=exit_ignore) + + if 't' in opts: + # timed execution + try: + nruns = int(opts['N'][0]) + if nruns < 1: + error('Number of runs must be >=1') + return + except (KeyError): + nruns = 1 + self._run_with_timing(run, nruns) + else: + # regular execution + run() + + if 'i' in opts: + self.shell.user_ns['__name__'] = __name__save + else: + # update IPython interactive namespace - # Some forms of read errors on the file may mean the - # __name__ key was never set; using pop we don't have to - # worry about a possible KeyError. - prog_ns.pop('__name__', None) + # Some forms of read errors on the file may mean the + # __name__ key was never set; using pop we don't have to + # worry about a possible KeyError. + prog_ns.pop('__name__', None) - with preserve_keys(self.shell.user_ns, '__file__'): - self.shell.user_ns.update(prog_ns) + with preserve_keys(self.shell.user_ns, '__file__'): + self.shell.user_ns.update(prog_ns) finally: # It's a bit of a mystery why, but __builtins__ can change from # being a module to becoming a dict missing some key data after diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 821e593..3e54d63 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -343,12 +343,6 @@ class InteractiveShellApp(Configurable): except: self.log.warning("Unknown error in handling PYTHONSTARTUP file %s:", python_startup) self.shell.showtraceback() - finally: - # Many PYTHONSTARTUP files set up the readline completions, - # but this is often at odds with IPython's own completions. - # Do not allow PYTHONSTARTUP to set up readline. - if self.shell.has_readline: - self.shell.set_readline_completer() startup_files += glob.glob(os.path.join(startup_dir, '*.py')) startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 3e636b3..7fc7c72 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -115,7 +115,6 @@ from inspect import getsourcefile, getfile, getmodule, \ ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode # IPython's own modules -# Modified pdb which doesn't damage IPython's readline handling from IPython import get_ipython from IPython.core import debugger from IPython.core.display_trap import DisplayTrap diff --git a/IPython/terminal/embed.py b/IPython/terminal/embed.py index 275cace..9cac1af 100644 --- a/IPython/terminal/embed.py +++ b/IPython/terminal/embed.py @@ -140,9 +140,6 @@ class InteractiveShellEmbed(TerminalInteractiveShell): if dummy or (dummy != 0 and self.dummy_mode): return - if self.has_readline: - self.set_readline_completer() - # self.banner is auto computed if header: self.old_banner2 = self.banner2