##// END OF EJS Templates
fix some deprecations...
Min RK -
Show More
@@ -109,7 +109,7 b' class DisplayHook(Configurable):'
109 109 """Write the output prompt.
110 110
111 111 The default implementation simply writes the prompt to
112 ``io.stdout``.
112 ``sys.stdout``.
113 113 """
114 114 # Use write, not print which adds an extra space.
115 115 sys.stdout.write(self.shell.separate_out)
@@ -156,7 +156,7 b' class DisplayHook(Configurable):'
156 156 """Write the format data dict to the frontend.
157 157
158 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 160 override this method to send the entire `format_dict` to the
161 161 frontends.
162 162
@@ -91,7 +91,7 b' class DisplayPublisher(Configurable):'
91 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 95 if 'text/plain' in data:
96 96 print(data['text/plain'])
97 97
@@ -588,7 +588,8 b' class PlainTextFormatter(BaseFormatter):'
588 588 # setter for float precision, either int or direct format-string
589 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 593 """float_precision changed, set float_format accordingly.
593 594
594 595 float_precision can be set by int or str.
@@ -602,6 +603,7 b' class PlainTextFormatter(BaseFormatter):'
602 603 This parameter can be set via the '%precision' magic.
603 604 """
604 605
606 new = change['new']
605 607 if '%' in new:
606 608 # got explicit format string
607 609 fmt = new
@@ -651,8 +651,12 b' class InteractiveShell(SingletonConfigurable):'
651 651 # override sys.stdout and sys.stderr themselves, you need to do that
652 652 # *before* instantiating this class, because io holds onto
653 653 # references to the underlying streams.
654 io.stdout = io.IOStream(sys.stdout)
655 io.stderr = io.IOStream(sys.stderr)
654 # io.std* are deprecated, but don't show our own deprecation warnings
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 661 def init_prompts(self):
658 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 24 from traitlets import (
25 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 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 35 backend_keys = sorted(pylabtools.backends.keys())
36 36 backend_keys.insert(0, 'auto')
@@ -1,24 +1,15 b''
1 1 """Tests for debugging machinery.
2 2 """
3 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 #-----------------------------------------------------------------------------
13 # Imports
14 #-----------------------------------------------------------------------------
5 # Copyright (c) IPython Development Team.
6 # Distributed under the terms of the Modified BSD License.
15 7
16 8 import sys
9 import warnings
17 10
18 # third-party
19 11 import nose.tools as nt
20 12
21 # Our own
22 13 from IPython.core import debugger
23 14
24 15 #-----------------------------------------------------------------------------
@@ -69,7 +60,9 b' def test_longer_repr():'
69 60 nt.assert_equal(trepr(a), a_trunc)
70 61 # The creation of our tracer modifies the repr module's repr function
71 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 66 nt.assert_equal(trepr(a), ar)
74 67
75 68 def test_ipdb_magics():
@@ -495,8 +495,8 b' class TBTools(colorable.Colorable):'
495 495
496 496 # Output stream to write to. Note that we store the original value in
497 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
499 # things are written now, the io.stdout object is dynamically managed
498 # that we can delay accessing sys.stdout until runtime. The way
499 # things are written now, the sys.stdout object is dynamically managed
500 500 # so a reference to it should NEVER be stored statically. This
501 501 # property approach confines this detail to a single location, and all
502 502 # subclasses can simply access self.ostream for writing.
@@ -509,7 +509,7 b' class TBTools(colorable.Colorable):'
509 509 self.old_scheme = color_scheme # save initial value for toggles
510 510
511 511 if call_pdb:
512 self.pdb = debugger.Pdb(self.color_scheme_table.active_scheme_name)
512 self.pdb = debugger.Pdb()
513 513 else:
514 514 self.pdb = None
515 515
@@ -519,7 +519,7 b' class TBTools(colorable.Colorable):'
519 519 Valid values are:
520 520
521 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 523 Windows (where plain stdout doesn't recognize ANSI escapes).
524 524
525 525 - Any object with 'write' and 'flush' attributes.
@@ -470,7 +470,7 b' class Demo(object):'
470 470 if self.block_index == self.nblocks:
471 471 mq1 = self.marquee('END OF DEMO')
472 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 474 print()
475 475 print(mq1)
476 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 30 raise FindCmdError
31 31
32 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 34 None)
35 35
36 36
@@ -40,7 +40,7 b' def test_latex_to_png_dvipng_runs():'
40 40 Test that latex_to_png_dvipng just runs without error.
41 41 """
42 42 def mock_kpsewhich(filename):
43 nt.assert_equals(filename, "breqn.sty")
43 nt.assert_equal(filename, "breqn.sty")
44 44 return None
45 45
46 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 55 Test that latex_to_png_mpl just runs without error.
56 56 """
57 57 def mock_kpsewhich(filename):
58 nt.assert_equals(filename, "breqn.sty")
58 nt.assert_equal(filename, "breqn.sty")
59 59 return None
60 60
61 61 for (s, wrap) in [("$x^2$", False), ("x^2", True)]:
@@ -79,7 +79,7 b' def test_genelatex_no_wrap():'
79 79 "(called with {0})".format(filename))
80 80
81 81 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
82 nt.assert_equals(
82 nt.assert_equal(
83 83 '\n'.join(latextools.genelatex("body text", False)),
84 84 r'''\documentclass{article}
85 85 \usepackage{amsmath}
@@ -97,11 +97,11 b' def test_genelatex_wrap_with_breqn():'
97 97 Test genelatex with wrap=True for the case breqn.sty is installed.
98 98 """
99 99 def mock_kpsewhich(filename):
100 nt.assert_equals(filename, "breqn.sty")
100 nt.assert_equal(filename, "breqn.sty")
101 101 return "path/to/breqn.sty"
102 102
103 103 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
104 nt.assert_equals(
104 nt.assert_equal(
105 105 '\n'.join(latextools.genelatex("x^2", True)),
106 106 r'''\documentclass{article}
107 107 \usepackage{amsmath}
@@ -122,11 +122,11 b' def test_genelatex_wrap_without_breqn():'
122 122 Test genelatex with wrap=True for the case breqn.sty is not installed.
123 123 """
124 124 def mock_kpsewhich(filename):
125 nt.assert_equals(filename, "breqn.sty")
125 nt.assert_equal(filename, "breqn.sty")
126 126 return None
127 127
128 128 with patch.object(latextools, "kpsewhich", mock_kpsewhich):
129 nt.assert_equals(
129 nt.assert_equal(
130 130 '\n'.join(latextools.genelatex("x^2", True)),
131 131 r'''\documentclass{article}
132 132 \usepackage{amsmath}
@@ -294,14 +294,13 b' class EmbeddedSphinxShell(object):'
294 294 IP = InteractiveShell.instance(config=config, profile_dir=profile)
295 295 atexit.register(self.cleanup)
296 296
297 # io.stdout redirect must be done after instantiating InteractiveShell
298 io.stdout = self.cout
299 io.stderr = self.cout
297 sys.stdout = self.cout
298 sys.stderr = self.cout
300 299
301 300 # For debugging, so we can see normal output, use this:
302 301 #from IPython.utils.io import Tee
303 #io.stdout = Tee(self.cout, channel='stdout') # dbg
304 #io.stderr = Tee(self.cout, channel='stderr') # dbg
302 #sys.stdout = Tee(self.cout, channel='stdout') # dbg
303 #sys.stderr = Tee(self.cout, channel='stderr') # dbg
305 304
306 305 # Store a few parts of IPython we'll need.
307 306 self.IP = IP
@@ -3,9 +3,11 b' from __future__ import print_function'
3 3
4 4 import os
5 5 import sys
6 import warnings
6 7 from warnings import warn
7 8
8 9 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
10 from IPython.utils import io
9 11 from IPython.utils.py3compat import PY3, cast_unicode_py2, input
10 12 from IPython.utils.terminal import toggle_set_term_title, set_term_title
11 13 from IPython.utils.process import abbrev_cwd
@@ -360,9 +362,12 b' class TerminalInteractiveShell(InteractiveShell):'
360 362 # For some reason we make these wrappers around stdout/stderr.
361 363 # For now, we need to reset them so all output gets coloured.
362 364 # https://github.com/ipython/ipython/issues/8669
363 from IPython.utils import io
364 io.stdout = io.IOStream(sys.stdout)
365 io.stderr = io.IOStream(sys.stderr)
365 # io.std* are deprecated, but don't show our own deprecation warnings
366 # during initialization of the deprecated API.
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 372 def init_magics(self):
368 373 super(TerminalInteractiveShell, self).init_magics()
@@ -8,21 +8,12 b' done.'
8 8 from __future__ import absolute_import
9 9 from __future__ import print_function
10 10
11 #-----------------------------------------------------------------------------
12 # Copyright (C) 2009-2011 The IPython Development Team
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
11 # Copyright (c) IPython Development Team.
12 # Distributed under the terms of the Modified BSD License.
13
23 14 import sys
15 import warnings
24 16
25 # our own
26 17 from . import tools
27 18
28 19 from IPython.core import page
@@ -31,9 +22,6 b' from IPython.utils import py3compat'
31 22 from IPython.utils.py3compat import builtin_mod
32 23 from IPython.terminal.interactiveshell import TerminalInteractiveShell
33 24
34 #-----------------------------------------------------------------------------
35 # Functions
36 #-----------------------------------------------------------------------------
37 25
38 26 class StreamProxy(io.IOStream):
39 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 36 def __init__(self, name):
37 warnings.warn("StreamProxy is deprecated and unused as of IPython 5", DeprecationWarning,
38 stacklevel=2,
39 )
49 40 self.name=name
50 41
51 42 @property
@@ -135,10 +126,6 b' def start_ipython():'
135 126 builtin_mod._ip = _ip
136 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 129 # Override paging, so we don't require user interaction during the tests.
143 130 def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
144 131 if isinstance(strng, dict):
@@ -14,6 +14,7 b' import atexit'
14 14 import os
15 15 import sys
16 16 import tempfile
17 import warnings
17 18 from warnings import warn
18 19
19 20 from IPython.utils.decorators import undoc
@@ -81,11 +82,16 b' class IOStream:'
81 82 pass
82 83
83 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 86 atexit.register(devnull.close)
86 stdin = IOStream(sys.stdin, fallback=devnull)
87 stdout = IOStream(sys.stdout, fallback=devnull)
88 stderr = IOStream(sys.stderr, fallback=devnull)
87
88 # io.std* are deprecated, but don't show our own deprecation warnings
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 96 class Tee(object):
91 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 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 23 Options:
24 24
General Comments 0
You need to be logged in to leave comments. Login now