From 65744c425bd28ad6f444bb8b3c6699454daa15e5 Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Sun, 8 Sep 2019 15:05:39 +0100 Subject: [PATCH 1/4] Replaced usage of deprecated module inputsplitter with inputtransformer2 --- rlipython/shell.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rlipython/shell.py b/rlipython/shell.py index bd5fabf..ca4ff2a 100644 --- a/rlipython/shell.py +++ b/rlipython/shell.py @@ -14,7 +14,7 @@ from IPython.core.error import TryNext, UsageError from IPython.core.usage import interactive_usage -from IPython.core.inputsplitter import ESC_MAGIC +from IPython.core.inputtransformer2 import ESC_MAGIC from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.terminal.magics import TerminalMagics from IPython.utils.contexts import NoOpContext @@ -513,6 +513,7 @@ def interact(self, display_banner=None): # exit_now is set by a call to %Exit or %Quit, through the # ask_exit callback. + self.lines_waiting = [] while not self.exit_now: self.hooks.pre_prompt_hook() if more: @@ -544,7 +545,8 @@ def interact(self, display_banner=None): #double-guard against keyboardinterrupts during kbdint handling try: self.write('\n' + self.get_exception_only()) - source_raw = self.input_splitter.raw_reset() + source_raw = ''.join(self.lines_waiting) + self.lines_waiting = [] hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) more = False @@ -568,8 +570,8 @@ def interact(self, display_banner=None): self.showtraceback() else: try: - self.input_splitter.push(line) - more = self.input_splitter.push_accepts_more() + self.lines_waiting.append(line) + more = self.input_splitter.check_complete(''.join(self.lines_waiting))[0] == 'incomplete' except SyntaxError: # Run the code directly - run_cell takes care of displaying # the exception. @@ -578,7 +580,8 @@ def interact(self, display_banner=None): self.autoedit_syntax): self.edit_syntax_error() if not more: - source_raw = self.input_splitter.raw_reset() + source_raw = ''.join(self.lines_waiting) + self.lines_waiting = [] self.run_cell(source_raw, store_history=True) hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) From 67e9ffcc963bd639a6528322e9cfad7398b0d981 Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Sat, 30 Nov 2019 11:46:26 +0000 Subject: [PATCH 2/4] Auto indent now works correctly on all platforms --- rlipython/shell.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rlipython/shell.py b/rlipython/shell.py index ca4ff2a..ad2cbff 100644 --- a/rlipython/shell.py +++ b/rlipython/shell.py @@ -152,6 +152,10 @@ class TerminalInteractiveShell(InteractiveShell): default.""", ) + # Store the number of spaces to use to indent the next line + # Can be either an integer or None + _indent_spaces = None + _term_reset = "\033[0m" # This is ugly because not only do we have a bunch of ansi escape # sequences, but we also have to wrap each escape code in \001 and \002 @@ -365,6 +369,11 @@ def pre_readline(self): self.readline.insert_text(self.rl_next_input) self.rl_next_input = None + def _indent_current_str(self): + """Return the current level of indentation as a string""" + n = 0 if self._indent_spaces is None else self._indent_spaces + return n * " " + def refill_readline_hist(self): # Load the last 1000 lines from history self.readline.clear_history() @@ -571,7 +580,9 @@ def interact(self, display_banner=None): else: try: self.lines_waiting.append(line) - more = self.input_splitter.check_complete(''.join(self.lines_waiting))[0] == 'incomplete' + status, next_indent = self.input_splitter.check_complete(''.join(self.lines_waiting)) + self._indent_spaces = next_indent + more = status == 'incomplete' except SyntaxError: # Run the code directly - run_cell takes care of displaying # the exception. From f3d01ffae08328ad5108d9d97ca6c12ac359f241 Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Sat, 30 Nov 2019 15:36:00 +0000 Subject: [PATCH 3/4] Multiline entries now work correctly --- rlipython/shell.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rlipython/shell.py b/rlipython/shell.py index ad2cbff..ac0346f 100644 --- a/rlipython/shell.py +++ b/rlipython/shell.py @@ -554,8 +554,9 @@ def interact(self, display_banner=None): #double-guard against keyboardinterrupts during kbdint handling try: self.write('\n' + self.get_exception_only()) - source_raw = ''.join(self.lines_waiting) + source_raw = '\n'.join(self.lines_waiting) self.lines_waiting = [] + self._indent_spaces = None hlen_b4_cell = \ self._replace_rlhist_multiline(source_raw, hlen_b4_cell) more = False @@ -580,7 +581,7 @@ def interact(self, display_banner=None): else: try: self.lines_waiting.append(line) - status, next_indent = self.input_splitter.check_complete(''.join(self.lines_waiting)) + status, next_indent = self.input_splitter.check_complete('\n'.join(self.lines_waiting)) self._indent_spaces = next_indent more = status == 'incomplete' except SyntaxError: @@ -591,7 +592,7 @@ def interact(self, display_banner=None): self.autoedit_syntax): self.edit_syntax_error() if not more: - source_raw = ''.join(self.lines_waiting) + source_raw = '\n'.join(self.lines_waiting) self.lines_waiting = [] self.run_cell(source_raw, store_history=True) hlen_b4_cell = \ From 574c4a9bd8fd0656ac21ece65ea59668eb638008 Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Sun, 1 Dec 2019 23:18:47 +0000 Subject: [PATCH 4/4] Updated setup.py with new ipython version requirement --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index e9a7c61..e093b1c 100644 --- a/setup.py +++ b/setup.py @@ -21,12 +21,12 @@ name='rlipython', version='0.1.2', packages=['rlipython',], - install_requires=["ipython>5.3"], + install_requires=["ipython>=7.0.0"], extras_requires=extras_requires, license='BSD', author='The IPython Development Team', author_email='ipython-dev@python.org', url='https://github.com/ipython/rlipython', - description="readline integration for IPython 5.4+ and 6.0+", + description="readline integration for IPython 7.0+", long_description=description )