##// END OF EJS Templates
Merge pull request #13397 from Carreau/enable-black-terminal...
Matthias Bussonnier -
r27326:e9a96bed merge
parent child Browse files
Show More
@@ -8,6 +8,7 b' import bdb'
8 import builtins
8 import builtins
9 import os
9 import os
10 import sys
10 import sys
11 import platform
11
12
12 from tempfile import NamedTemporaryFile
13 from tempfile import NamedTemporaryFile
13 from textwrap import dedent
14 from textwrap import dedent
@@ -16,6 +17,7 b' from unittest.mock import patch'
16 from IPython.core import debugger
17 from IPython.core import debugger
17 from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE
18 from IPython.testing import IPYTHON_TESTING_TIMEOUT_SCALE
18 from IPython.testing.decorators import skip_win32
19 from IPython.testing.decorators import skip_win32
20 import pytest
19
21
20 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
21 # Helper classes, from CPython's Pdb test suite
23 # Helper classes, from CPython's Pdb test suite
@@ -411,6 +413,7 b' def test_decorator_skip():'
411 child.close()
413 child.close()
412
414
413
415
416 @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy")
414 @skip_win32
417 @skip_win32
415 def test_decorator_skip_disabled():
418 def test_decorator_skip_disabled():
416 """test that decorator frame skipping can be disabled"""
419 """test that decorator frame skipping can be disabled"""
@@ -438,6 +441,7 b' def test_decorator_skip_disabled():'
438 child.close()
441 child.close()
439
442
440
443
444 @pytest.mark.skip(platform.python_implementation() == "PyPy", reason="issues on PyPy")
441 @skip_win32
445 @skip_win32
442 def test_decorator_skip_with_breakpoint():
446 def test_decorator_skip_with_breakpoint():
443 """test that decorator frame skipping can be disabled"""
447 """test that decorator frame skipping can be disabled"""
@@ -102,10 +102,16 b' else:'
102 _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty)
102 _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty)
103
103
104 def black_reformat_handler(text_before_cursor):
104 def black_reformat_handler(text_before_cursor):
105 """
106 We do not need to protect against error,
107 this is taken care at a higher level where any reformat error is ignored.
108 Indeed we may call reformatting on incomplete code.
109 """
105 import black
110 import black
111
106 formatted_text = black.format_str(text_before_cursor, mode=black.FileMode())
112 formatted_text = black.format_str(text_before_cursor, mode=black.FileMode())
107 if not text_before_cursor.endswith('\n') and formatted_text.endswith('\n'):
113 if not text_before_cursor.endswith("\n") and formatted_text.endswith("\n"):
108 formatted_text = formatted_text[:-1]
114 formatted_text = formatted_text[:-1]
109 return formatted_text
115 return formatted_text
110
116
111
117
@@ -176,7 +182,8 b' class TerminalInteractiveShell(InteractiveShell):'
176 sequence to complete.""",
182 sequence to complete.""",
177 ).tag(config=True)
183 ).tag(config=True)
178
184
179 autoformatter = Unicode(None,
185 autoformatter = Unicode(
186 "black",
180 help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`",
187 help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`",
181 allow_none=True
188 allow_none=True
182 ).tag(config=True)
189 ).tag(config=True)
@@ -210,9 +217,7 b' class TerminalInteractiveShell(InteractiveShell):'
210 if self.pt_app:
217 if self.pt_app:
211 self.pt_app.editing_mode = getattr(EditingMode, change.new.upper())
218 self.pt_app.editing_mode = getattr(EditingMode, change.new.upper())
212
219
213 @observe('autoformatter')
220 def _set_formatter(self, formatter):
214 def _autoformatter_changed(self, change):
215 formatter = change.new
216 if formatter is None:
221 if formatter is None:
217 self.reformat_handler = lambda x:x
222 self.reformat_handler = lambda x:x
218 elif formatter == 'black':
223 elif formatter == 'black':
@@ -220,6 +225,11 b' class TerminalInteractiveShell(InteractiveShell):'
220 else:
225 else:
221 raise ValueError
226 raise ValueError
222
227
228 @observe("autoformatter")
229 def _autoformatter_changed(self, change):
230 formatter = change.new
231 self._set_formatter(formatter)
232
223 @observe('highlighting_style')
233 @observe('highlighting_style')
224 @observe('colors')
234 @observe('colors')
225 def _highlighting_style_changed(self, change):
235 def _highlighting_style_changed(self, change):
@@ -561,6 +571,7 b' class TerminalInteractiveShell(InteractiveShell):'
561 self.init_prompt_toolkit_cli()
571 self.init_prompt_toolkit_cli()
562 self.init_term_title()
572 self.init_term_title()
563 self.keep_running = True
573 self.keep_running = True
574 self._set_formatter(self.autoformatter)
564
575
565
576
566 def ask_exit(self):
577 def ask_exit(self):
@@ -31,6 +31,7 b' zip_safe = False'
31 install_requires =
31 install_requires =
32 setuptools>=18.5
32 setuptools>=18.5
33 jedi>=0.16
33 jedi>=0.16
34 black
34 decorator
35 decorator
35 pickleshare
36 pickleshare
36 traitlets>=5
37 traitlets>=5
General Comments 0
You need to be logged in to leave comments. Login now