##// END OF EJS Templates
Merge pull request #9823 from minrk/deprecations...
Thomas Kluyver -
r22743:bf3b45fb merge
parent child Browse files
Show More
@@ -109,7 +109,7 b' class DisplayHook(Configurable):'
109 """Write the output prompt.
109 """Write the output prompt.
110
110
111 The default implementation simply writes the prompt to
111 The default implementation simply writes the prompt to
112 ``io.stdout``.
112 ``sys.stdout``.
113 """
113 """
114 # Use write, not print which adds an extra space.
114 # Use write, not print which adds an extra space.
115 sys.stdout.write(self.shell.separate_out)
115 sys.stdout.write(self.shell.separate_out)
@@ -156,7 +156,7 b' class DisplayHook(Configurable):'
156 """Write the format data dict to the frontend.
156 """Write the format data dict to the frontend.
157
157
158 This default version of this method simply writes the plain text
158 This default version of this method simply writes the plain text
159 representation of the object to ``io.stdout``. Subclasses should
159 representation of the object to ``sys.stdout``. Subclasses should
160 override this method to send the entire `format_dict` to the
160 override this method to send the entire `format_dict` to the
161 frontends.
161 frontends.
162
162
@@ -91,7 +91,7 b' class DisplayPublisher(Configurable):'
91 Unused.
91 Unused.
92 """
92 """
93
93
94 # The default is to simply write the plain text data using io.stdout.
94 # The default is to simply write the plain text data using sys.stdout.
95 if 'text/plain' in data:
95 if 'text/plain' in data:
96 print(data['text/plain'])
96 print(data['text/plain'])
97
97
@@ -588,7 +588,8 b' class PlainTextFormatter(BaseFormatter):'
588 # setter for float precision, either int or direct format-string
588 # setter for float precision, either int or direct format-string
589 float_precision = CUnicode('').tag(config=True)
589 float_precision = CUnicode('').tag(config=True)
590
590
591 def _float_precision_changed(self, name, old, new):
591 @observe('float_precision')
592 def _float_precision_changed(self, change):
592 """float_precision changed, set float_format accordingly.
593 """float_precision changed, set float_format accordingly.
593
594
594 float_precision can be set by int or str.
595 float_precision can be set by int or str.
@@ -602,6 +603,7 b' class PlainTextFormatter(BaseFormatter):'
602 This parameter can be set via the '%precision' magic.
603 This parameter can be set via the '%precision' magic.
603 """
604 """
604
605
606 new = change['new']
605 if '%' in new:
607 if '%' in new:
606 # got explicit format string
608 # got explicit format string
607 fmt = new
609 fmt = new
@@ -651,8 +651,12 b' class InteractiveShell(SingletonConfigurable):'
651 # override sys.stdout and sys.stderr themselves, you need to do that
651 # override sys.stdout and sys.stderr themselves, you need to do that
652 # *before* instantiating this class, because io holds onto
652 # *before* instantiating this class, because io holds onto
653 # references to the underlying streams.
653 # references to the underlying streams.
654 io.stdout = io.IOStream(sys.stdout)
654 # io.std* are deprecated, but don't show our own deprecation warnings
655 io.stderr = io.IOStream(sys.stderr)
655 # during initialization of the deprecated API.
656 with warnings.catch_warnings():
657 warnings.simplefilter('ignore', DeprecationWarning)
658 io.stdout = io.IOStream(sys.stdout)
659 io.stderr = io.IOStream(sys.stderr)
656
660
657 def init_prompts(self):
661 def init_prompts(self):
658 # Set system prompts, so that scripts can decide if they are running
662 # Set system prompts, so that scripts can decide if they are running
@@ -24,13 +24,13 b' from IPython.utils.path import filefind'
24 from traitlets import (
24 from traitlets import (
25 Unicode, Instance, List, Bool, CaselessStrEnum, observe,
25 Unicode, Instance, List, Bool, CaselessStrEnum, observe,
26 )
26 )
27 from IPython.lib.inputhook import guis
27 from IPython.terminal import pt_inputhooks
28
28
29 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
30 # Aliases and Flags
30 # Aliases and Flags
31 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
32
32
33 gui_keys = tuple(sorted([ key for key in guis if key is not None ]))
33 gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases))
34
34
35 backend_keys = sorted(pylabtools.backends.keys())
35 backend_keys = sorted(pylabtools.backends.keys())
36 backend_keys.insert(0, 'auto')
36 backend_keys.insert(0, 'auto')
@@ -1,24 +1,15 b''
1 """Tests for debugging machinery.
1 """Tests for debugging machinery.
2 """
2 """
3 from __future__ import print_function
3 from __future__ import print_function
4 #-----------------------------------------------------------------------------
5 # Copyright (c) 2012, The IPython Development Team.
6 #
7 # Distributed under the terms of the Modified BSD License.
8 #
9 # The full license is in the file COPYING.txt, distributed with this software.
10 #-----------------------------------------------------------------------------
11
4
12 #-----------------------------------------------------------------------------
5 # Copyright (c) IPython Development Team.
13 # Imports
6 # Distributed under the terms of the Modified BSD License.
14 #-----------------------------------------------------------------------------
15
7
16 import sys
8 import sys
9 import warnings
17
10
18 # third-party
19 import nose.tools as nt
11 import nose.tools as nt
20
12
21 # Our own
22 from IPython.core import debugger
13 from IPython.core import debugger
23
14
24 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
@@ -69,7 +60,9 b' def test_longer_repr():'
69 nt.assert_equal(trepr(a), a_trunc)
60 nt.assert_equal(trepr(a), a_trunc)
70 # The creation of our tracer modifies the repr module's repr function
61 # The creation of our tracer modifies the repr module's repr function
71 # in-place, since that global is used directly by the stdlib's pdb module.
62 # in-place, since that global is used directly by the stdlib's pdb module.
72 debugger.Tracer()
63 with warnings.catch_warnings():
64 warnings.simplefilter('ignore', DeprecationWarning)
65 debugger.Tracer()
73 nt.assert_equal(trepr(a), ar)
66 nt.assert_equal(trepr(a), ar)
74
67
75 def test_ipdb_magics():
68 def test_ipdb_magics():
@@ -495,8 +495,8 b' class TBTools(colorable.Colorable):'
495
495
496 # Output stream to write to. Note that we store the original value in
496 # Output stream to write to. Note that we store the original value in
497 # a private attribute and then make the public ostream a property, so
497 # a private attribute and then make the public ostream a property, so
498 # that we can delay accessing io.stdout until runtime. The way
498 # that we can delay accessing sys.stdout until runtime. The way
499 # things are written now, the io.stdout object is dynamically managed
499 # things are written now, the sys.stdout object is dynamically managed
500 # so a reference to it should NEVER be stored statically. This
500 # so a reference to it should NEVER be stored statically. This
501 # property approach confines this detail to a single location, and all
501 # property approach confines this detail to a single location, and all
502 # subclasses can simply access self.ostream for writing.
502 # subclasses can simply access self.ostream for writing.
@@ -509,7 +509,7 b' class TBTools(colorable.Colorable):'
509 self.old_scheme = color_scheme # save initial value for toggles
509 self.old_scheme = color_scheme # save initial value for toggles
510
510
511 if call_pdb:
511 if call_pdb:
512 self.pdb = debugger.Pdb(self.color_scheme_table.active_scheme_name)
512 self.pdb = debugger.Pdb()
513 else:
513 else:
514 self.pdb = None
514 self.pdb = None
515
515
@@ -519,7 +519,7 b' class TBTools(colorable.Colorable):'
519 Valid values are:
519 Valid values are:
520
520
521 - None: the default, which means that IPython will dynamically resolve
521 - None: the default, which means that IPython will dynamically resolve
522 to io.stdout. This ensures compatibility with most tools, including
522 to sys.stdout. This ensures compatibility with most tools, including
523 Windows (where plain stdout doesn't recognize ANSI escapes).
523 Windows (where plain stdout doesn't recognize ANSI escapes).
524
524
525 - Any object with 'write' and 'flush' attributes.
525 - Any object with 'write' and 'flush' attributes.
@@ -470,7 +470,7 b' class Demo(object):'
470 if self.block_index == self.nblocks:
470 if self.block_index == self.nblocks:
471 mq1 = self.marquee('END OF DEMO')
471 mq1 = self.marquee('END OF DEMO')
472 if mq1:
472 if mq1:
473 # avoid spurious print >>io.stdout,s if empty marquees are used
473 # avoid spurious print if empty marquees are used
474 print()
474 print()
475 print(mq1)
475 print(mq1)
476 print(self.marquee('Use <demo_name>.reset() if you want to rerun it.'))
476 print(self.marquee('Use <demo_name>.reset() if you want to rerun it.'))
@@ -30,7 +30,7 b' def check_latex_to_png_dvipng_fails_when_no_cmd(command):'
30 raise FindCmdError
30 raise FindCmdError
31
31
32 with patch.object(latextools, "find_cmd", mock_find_cmd):
32 with patch.object(latextools, "find_cmd", mock_find_cmd):
33 nt.assert_equals(latextools.latex_to_png_dvipng("whatever", True),
33 nt.assert_equal(latextools.latex_to_png_dvipng("whatever", True),
34 None)
34 None)
35
35
36
36
@@ -40,7 +40,7 b' def test_latex_to_png_dvipng_runs():'
40 Test that latex_to_png_dvipng just runs without error.
40 Test that latex_to_png_dvipng just runs without error.
41 """
41 """
42 def mock_kpsewhich(filename):
42 def mock_kpsewhich(filename):
43 nt.assert_equals(filename, "breqn.sty")
43 nt.assert_equal(filename, "breqn.sty")
44 return None
44 return None
45
45
46 for (s, wrap) in [(u"$$x^2$$", False), (u"x^2", True)]:
46 for (s, wrap) in [(u"$$x^2$$", False), (u"x^2", True)]:
@@ -55,7 +55,7 b' def test_latex_to_png_mpl_runs():'
55 Test that latex_to_png_mpl just runs without error.
55 Test that latex_to_png_mpl just runs without error.
56 """
56 """
57 def mock_kpsewhich(filename):
57 def mock_kpsewhich(filename):
58 nt.assert_equals(filename, "breqn.sty")
58 nt.assert_equal(filename, "breqn.sty")
59 return None
59 return None
60
60
61 for (s, wrap) in [("$x^2$", False), ("x^2", True)]:
61 for (s, wrap) in [("$x^2$", False), ("x^2", True)]:
@@ -79,7 +79,7 b' def test_genelatex_no_wrap():'
79 "(called with {0})".format(filename))
79 "(called with {0})".format(filename))
80
80
81 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
81 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
82 nt.assert_equals(
82 nt.assert_equal(
83 '\n'.join(latextools.genelatex("body text", False)),
83 '\n'.join(latextools.genelatex("body text", False)),
84 r'''\documentclass{article}
84 r'''\documentclass{article}
85 \usepackage{amsmath}
85 \usepackage{amsmath}
@@ -97,11 +97,11 b' def test_genelatex_wrap_with_breqn():'
97 Test genelatex with wrap=True for the case breqn.sty is installed.
97 Test genelatex with wrap=True for the case breqn.sty is installed.
98 """
98 """
99 def mock_kpsewhich(filename):
99 def mock_kpsewhich(filename):
100 nt.assert_equals(filename, "breqn.sty")
100 nt.assert_equal(filename, "breqn.sty")
101 return "path/to/breqn.sty"
101 return "path/to/breqn.sty"
102
102
103 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
103 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
104 nt.assert_equals(
104 nt.assert_equal(
105 '\n'.join(latextools.genelatex("x^2", True)),
105 '\n'.join(latextools.genelatex("x^2", True)),
106 r'''\documentclass{article}
106 r'''\documentclass{article}
107 \usepackage{amsmath}
107 \usepackage{amsmath}
@@ -122,11 +122,11 b' def test_genelatex_wrap_without_breqn():'
122 Test genelatex with wrap=True for the case breqn.sty is not installed.
122 Test genelatex with wrap=True for the case breqn.sty is not installed.
123 """
123 """
124 def mock_kpsewhich(filename):
124 def mock_kpsewhich(filename):
125 nt.assert_equals(filename, "breqn.sty")
125 nt.assert_equal(filename, "breqn.sty")
126 return None
126 return None
127
127
128 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
128 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
129 nt.assert_equals(
129 nt.assert_equal(
130 '\n'.join(latextools.genelatex("x^2", True)),
130 '\n'.join(latextools.genelatex("x^2", True)),
131 r'''\documentclass{article}
131 r'''\documentclass{article}
132 \usepackage{amsmath}
132 \usepackage{amsmath}
@@ -294,14 +294,13 b' class EmbeddedSphinxShell(object):'
294 IP = InteractiveShell.instance(config=config, profile_dir=profile)
294 IP = InteractiveShell.instance(config=config, profile_dir=profile)
295 atexit.register(self.cleanup)
295 atexit.register(self.cleanup)
296
296
297 # io.stdout redirect must be done after instantiating InteractiveShell
297 sys.stdout = self.cout
298 io.stdout = self.cout
298 sys.stderr = self.cout
299 io.stderr = self.cout
300
299
301 # For debugging, so we can see normal output, use this:
300 # For debugging, so we can see normal output, use this:
302 #from IPython.utils.io import Tee
301 #from IPython.utils.io import Tee
303 #io.stdout = Tee(self.cout, channel='stdout') # dbg
302 #sys.stdout = Tee(self.cout, channel='stdout') # dbg
304 #io.stderr = Tee(self.cout, channel='stderr') # dbg
303 #sys.stderr = Tee(self.cout, channel='stderr') # dbg
305
304
306 # Store a few parts of IPython we'll need.
305 # Store a few parts of IPython we'll need.
307 self.IP = IP
306 self.IP = IP
@@ -3,9 +3,11 b' from __future__ import print_function'
3
3
4 import os
4 import os
5 import sys
5 import sys
6 import warnings
6 from warnings import warn
7 from warnings import warn
7
8
8 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
9 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
10 from IPython.utils import io
9 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
11 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
10 from IPython.utils.terminal import toggle_set_term_title, set_term_title
12 from IPython.utils.terminal import toggle_set_term_title, set_term_title
11 from IPython.utils.process import abbrev_cwd
13 from IPython.utils.process import abbrev_cwd
@@ -360,9 +362,12 b' class TerminalInteractiveShell(InteractiveShell):'
360 # For some reason we make these wrappers around stdout/stderr.
362 # For some reason we make these wrappers around stdout/stderr.
361 # For now, we need to reset them so all output gets coloured.
363 # For now, we need to reset them so all output gets coloured.
362 # https://github.com/ipython/ipython/issues/8669
364 # https://github.com/ipython/ipython/issues/8669
363 from IPython.utils import io
365 # io.std* are deprecated, but don't show our own deprecation warnings
364 io.stdout = io.IOStream(sys.stdout)
366 # during initialization of the deprecated API.
365 io.stderr = io.IOStream(sys.stderr)
367 with warnings.catch_warnings():
368 warnings.simplefilter('ignore', DeprecationWarning)
369 io.stdout = io.IOStream(sys.stdout)
370 io.stderr = io.IOStream(sys.stderr)
366
371
367 def init_magics(self):
372 def init_magics(self):
368 super(TerminalInteractiveShell, self).init_magics()
373 super(TerminalInteractiveShell, self).init_magics()
@@ -8,21 +8,12 b' done.'
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9 from __future__ import print_function
9 from __future__ import print_function
10
10
11 #-----------------------------------------------------------------------------
11 # Copyright (c) IPython Development Team.
12 # Copyright (C) 2009-2011 The IPython Development Team
12 # Distributed under the terms of the Modified BSD License.
13 #
13
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
16 #-----------------------------------------------------------------------------
17
18 #-----------------------------------------------------------------------------
19 # Imports
20 #-----------------------------------------------------------------------------
21
22 # stdlib
23 import sys
14 import sys
15 import warnings
24
16
25 # our own
26 from . import tools
17 from . import tools
27
18
28 from IPython.core import page
19 from IPython.core import page
@@ -31,9 +22,6 b' from IPython.utils import py3compat'
31 from IPython.utils.py3compat import builtin_mod
22 from IPython.utils.py3compat import builtin_mod
32 from IPython.terminal.interactiveshell import TerminalInteractiveShell
23 from IPython.terminal.interactiveshell import TerminalInteractiveShell
33
24
34 #-----------------------------------------------------------------------------
35 # Functions
36 #-----------------------------------------------------------------------------
37
25
38 class StreamProxy(io.IOStream):
26 class StreamProxy(io.IOStream):
39 """Proxy for sys.stdout/err. This will request the stream *at call time*
27 """Proxy for sys.stdout/err. This will request the stream *at call time*
@@ -46,6 +34,9 b' class StreamProxy(io.IOStream):'
46 """
34 """
47
35
48 def __init__(self, name):
36 def __init__(self, name):
37 warnings.warn("StreamProxy is deprecated and unused as of IPython 5", DeprecationWarning,
38 stacklevel=2,
39 )
49 self.name=name
40 self.name=name
50
41
51 @property
42 @property
@@ -135,10 +126,6 b' def start_ipython():'
135 builtin_mod._ip = _ip
126 builtin_mod._ip = _ip
136 builtin_mod.get_ipython = get_ipython
127 builtin_mod.get_ipython = get_ipython
137
128
138 # To avoid extra IPython messages during testing, suppress io.stdout/stderr
139 io.stdout = StreamProxy('stdout')
140 io.stderr = StreamProxy('stderr')
141
142 # Override paging, so we don't require user interaction during the tests.
129 # Override paging, so we don't require user interaction during the tests.
143 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
130 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
144 if isinstance(strng, dict):
131 if isinstance(strng, dict):
@@ -14,6 +14,7 b' import atexit'
14 import os
14 import os
15 import sys
15 import sys
16 import tempfile
16 import tempfile
17 import warnings
17 from warnings import warn
18 from warnings import warn
18
19
19 from IPython.utils.decorators import undoc
20 from IPython.utils.decorators import undoc
@@ -81,11 +82,16 b' class IOStream:'
81 pass
82 pass
82
83
83 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
84 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
84 devnull = open(os.devnull, 'w')
85 devnull = open(os.devnull, 'w')
85 atexit.register(devnull.close)
86 atexit.register(devnull.close)
86 stdin = IOStream(sys.stdin, fallback=devnull)
87
87 stdout = IOStream(sys.stdout, fallback=devnull)
88 # io.std* are deprecated, but don't show our own deprecation warnings
88 stderr = IOStream(sys.stderr, fallback=devnull)
89 # during initialization of the deprecated API.
90 with warnings.catch_warnings():
91 warnings.simplefilter('ignore', DeprecationWarning)
92 stdin = IOStream(sys.stdin, fallback=devnull)
93 stdout = IOStream(sys.stdout, fallback=devnull)
94 stderr = IOStream(sys.stderr, fallback=devnull)
89
95
90 class Tee(object):
96 class Tee(object):
91 """A class to duplicate an output stream to stdout/err.
97 """A class to duplicate an output stream to stdout/err.
@@ -18,7 +18,7 b' def warn(msg,level=2,exit_val=1):'
18
18
19 Standard warning printer. Gives formatting consistency.
19 Standard warning printer. Gives formatting consistency.
20
20
21 Output is sent to io.stderr (sys.stderr by default).
21 Output is sent to sys.stderr.
22
22
23 Options:
23 Options:
24
24
General Comments 0
You need to be logged in to leave comments. Login now