##// END OF EJS Templates
Merge pull request #13355 from Carreau/deprecation-removal-2...
Matthias Bussonnier -
r27212:3e89cd47 merge
parent child Browse files
Show More
@@ -712,16 +712,9 b' class InteractiveShell(SingletonConfigurable):'
712 self.object_info_string_level)
712 self.object_info_string_level)
713
713
714 def init_io(self):
714 def init_io(self):
715 # This will just use sys.stdout and sys.stderr. If you want to
715 # implemented in subclasses, TerminalInteractiveShell does call
716 # override sys.stdout and sys.stderr themselves, you need to do that
716 # colorama.init().
717 # *before* instantiating this class, because io holds onto
717 pass
718 # references to the underlying streams.
719 # io.std* are deprecated, but don't show our own deprecation warnings
720 # during initialization of the deprecated API.
721 with warnings.catch_warnings():
722 warnings.simplefilter('ignore', DeprecationWarning)
723 io.stdout = io.IOStream(sys.stdout)
724 io.stderr = io.IOStream(sys.stderr)
725
718
726 def init_prompts(self):
719 def init_prompts(self):
727 # Set system prompts, so that scripts can decide if they are running
720 # Set system prompts, so that scripts can decide if they are running
@@ -540,16 +540,6 b' class TerminalInteractiveShell(InteractiveShell):'
540 import colorama
540 import colorama
541 colorama.init()
541 colorama.init()
542
542
543 # For some reason we make these wrappers around stdout/stderr.
544 # For now, we need to reset them so all output gets coloured.
545 # https://github.com/ipython/ipython/issues/8669
546 # io.std* are deprecated, but don't show our own deprecation warnings
547 # during initialization of the deprecated API.
548 with warnings.catch_warnings():
549 warnings.simplefilter('ignore', DeprecationWarning)
550 io.stdout = io.IOStream(sys.stdout)
551 io.stderr = io.IOStream(sys.stderr)
552
553 def init_magics(self):
543 def init_magics(self):
554 super(TerminalInteractiveShell, self).init_magics()
544 super(TerminalInteractiveShell, self).init_magics()
555 self.register_magics(TerminalMagics)
545 self.register_magics(TerminalMagics)
@@ -23,30 +23,6 b' from IPython.utils import io'
23 from IPython.terminal.interactiveshell import TerminalInteractiveShell
23 from IPython.terminal.interactiveshell import TerminalInteractiveShell
24
24
25
25
26 class StreamProxy(io.IOStream):
27 """Proxy for sys.stdout/err. This will request the stream *at call time*
28 allowing for nose's Capture plugin's redirection of sys.stdout/err.
29
30 Parameters
31 ----------
32 name : str
33 The name of the stream. This will be requested anew at every call
34 """
35
36 def __init__(self, name):
37 warnings.warn("StreamProxy is deprecated and unused as of IPython 5", DeprecationWarning,
38 stacklevel=2,
39 )
40 self.name=name
41
42 @property
43 def stream(self):
44 return getattr(sys, self.name)
45
46 def flush(self):
47 self.stream.flush()
48
49
50 def get_ipython():
26 def get_ipython():
51 # This will get replaced by the real thing once we start IPython below
27 # This will get replaced by the real thing once we start IPython below
52 return start_ipython()
28 return start_ipython()
@@ -19,82 +19,10 b' from warnings import warn'
19 from IPython.utils.decorators import undoc
19 from IPython.utils.decorators import undoc
20 from .capture import CapturedIO, capture_output
20 from .capture import CapturedIO, capture_output
21
21
22 @undoc
23 class IOStream:
24
25 def __init__(self, stream, fallback=None):
26 warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead',
27 DeprecationWarning, stacklevel=2)
28 if not hasattr(stream,'write') or not hasattr(stream,'flush'):
29 if fallback is not None:
30 stream = fallback
31 else:
32 raise ValueError("fallback required, but not specified")
33 self.stream = stream
34 self._swrite = stream.write
35
36 # clone all methods not overridden:
37 def clone(meth):
38 return not hasattr(self, meth) and not meth.startswith('_')
39 for meth in filter(clone, dir(stream)):
40 try:
41 val = getattr(stream, meth)
42 except AttributeError:
43 pass
44 else:
45 setattr(self, meth, val)
46
47 def __repr__(self):
48 cls = self.__class__
49 tpl = '{mod}.{cls}({args})'
50 return tpl.format(mod=cls.__module__, cls=cls.__name__, args=self.stream)
51
52 def write(self,data):
53 warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead',
54 DeprecationWarning, stacklevel=2)
55 try:
56 self._swrite(data)
57 except:
58 try:
59 # print handles some unicode issues which may trip a plain
60 # write() call. Emulate write() by using an empty end
61 # argument.
62 print(data, end='', file=self.stream)
63 except:
64 # if we get here, something is seriously broken.
65 print('ERROR - failed to write data to stream:', self.stream,
66 file=sys.stderr)
67
68 def writelines(self, lines):
69 warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead',
70 DeprecationWarning, stacklevel=2)
71 if isinstance(lines, str):
72 lines = [lines]
73 for line in lines:
74 self.write(line)
75
76 # This class used to have a writeln method, but regular files and streams
77 # in Python don't have this method. We need to keep this completely
78 # compatible so we removed it.
79
80 @property
81 def closed(self):
82 return self.stream.closed
83
84 def close(self):
85 pass
86
87 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
22 # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr
88 devnull = open(os.devnull, 'w')
23 devnull = open(os.devnull, 'w')
89 atexit.register(devnull.close)
24 atexit.register(devnull.close)
90
25
91 # io.std* are deprecated, but don't show our own deprecation warnings
92 # during initialization of the deprecated API.
93 with warnings.catch_warnings():
94 warnings.simplefilter('ignore', DeprecationWarning)
95 stdin = IOStream(sys.stdin, fallback=devnull)
96 stdout = IOStream(sys.stdout, fallback=devnull)
97 stderr = IOStream(sys.stderr, fallback=devnull)
98
26
99 class Tee(object):
27 class Tee(object):
100 """A class to duplicate an output stream to stdout/err.
28 """A class to duplicate an output stream to stdout/err.
@@ -208,12 +136,6 b" def temp_pyfile(src, ext='.py'):"
208 f.flush()
136 f.flush()
209 return fname
137 return fname
210
138
211 @undoc
212 def atomic_writing(*args, **kwargs):
213 """DEPRECATED: moved to notebook.services.contents.fileio"""
214 warn("IPython.utils.io.atomic_writing has moved to notebook.services.contents.fileio since IPython 4.0", DeprecationWarning, stacklevel=2)
215 from notebook.services.contents.fileio import atomic_writing
216 return atomic_writing(*args, **kwargs)
217
139
218 @undoc
140 @undoc
219 def raw_print(*args, **kw):
141 def raw_print(*args, **kw):
@@ -232,10 +154,3 b' def raw_print_err(*args, **kw):'
232 print(*args, sep=kw.get('sep', ' '), end=kw.get('end', '\n'),
154 print(*args, sep=kw.get('sep', ' '), end=kw.get('end', '\n'),
233 file=sys.__stderr__)
155 file=sys.__stderr__)
234 sys.__stderr__.flush()
156 sys.__stderr__.flush()
235
236 @undoc
237 def unicode_std_stream(stream='stdout'):
238 """DEPRECATED, moved to nbconvert.utils.io"""
239 warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io since IPython 4.0", DeprecationWarning, stacklevel=2)
240 from nbconvert.utils.io import unicode_std_stream
241 return unicode_std_stream(stream)
@@ -11,7 +11,7 b' from io import StringIO'
11 from subprocess import Popen, PIPE
11 from subprocess import Popen, PIPE
12 import unittest
12 import unittest
13
13
14 from IPython.utils.io import IOStream, Tee, capture_output
14 from IPython.utils.io import Tee, capture_output
15
15
16
16
17 def test_tee_simple():
17 def test_tee_simple():
@@ -48,34 +48,8 b' class TeeTestCase(unittest.TestCase):'
48 for chan in ['stdout', 'stderr']:
48 for chan in ['stdout', 'stderr']:
49 self.tchan(chan)
49 self.tchan(chan)
50
50
51 def test_io_init():
52 """Test that io.stdin/out/err exist at startup"""
53 for name in ('stdin', 'stdout', 'stderr'):
54 cmd = "from IPython.utils import io;print(io.%s.__class__)"%name
55 with Popen([sys.executable, '-c', cmd], stdout=PIPE) as p:
56 p.wait()
57 classname = p.stdout.read().strip().decode('ascii')
58 # __class__ is a reference to the class object in Python 3, so we can't
59 # just test for string equality.
60 assert 'IPython.utils.io.IOStream' in classname, classname
61
62 class TestIOStream(unittest.TestCase):
51 class TestIOStream(unittest.TestCase):
63
52
64 def test_IOStream_init(self):
65 """IOStream initializes from a file-like object missing attributes. """
66 # Cause a failure from getattr and dir(). (Issue #6386)
67 class BadStringIO(StringIO):
68 def __dir__(self):
69 attrs = super().__dir__()
70 attrs.append('name')
71 return attrs
72 with self.assertWarns(DeprecationWarning):
73 iostream = IOStream(BadStringIO())
74 iostream.write('hi, bad iostream\n')
75
76 assert not hasattr(iostream, 'name')
77 iostream.close()
78
79 def test_capture_output(self):
53 def test_capture_output(self):
80 """capture_output() context works"""
54 """capture_output() context works"""
81
55
General Comments 0
You need to be logged in to leave comments. Login now