From 2b1e9efdc390bf3a0f989d67bb8d5be58cfda306 2014-04-16 21:34:19 From: MinRK Date: 2014-04-16 21:34:19 Subject: [PATCH] Backport PR #5582: reset readline after running PYTHONSTARTUP should avoid conflicts between IPython and Python completion setup Many folks have completion setup in PYTHONSTARTUP for the plain Python REPL. In IPython 1.x, this wasn't an issue because IPython reset the readline state after every execution. This was removed in 2.0 (#4353), allowing users to customize readline behavior. One effect of this is allowing PYTHONSTARTUP to customize *IPython's* readline behavior, which seems to be something nobody wants. This PR simply re-applies the old reset readline behavior after running PYTHONSTARTUP. closes #5514 --- diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index 159d530..8597da3 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -358,9 +358,23 @@ class InteractiveShellApp(Configurable): """Run files from profile startup directory""" startup_dir = self.profile_dir.startup_dir startup_files = [] - if self.exec_PYTHONSTARTUP and not (self.file_to_run or self.code_to_run or self.module_to_run): - if os.environ.get('PYTHONSTARTUP', False): - startup_files.append(os.environ['PYTHONSTARTUP']) + + if self.exec_PYTHONSTARTUP and os.environ.get('PYTHONSTARTUP', False) and \ + not (self.file_to_run or self.code_to_run or self.module_to_run): + python_startup = os.environ['PYTHONSTARTUP'] + self.log.debug("Running PYTHONSTARTUP file %s...", python_startup) + try: + self._exec_file(python_startup) + except: + self.log.warn("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')) if not startup_files: