Show More
@@ -102,7 +102,6 b' All the changes since then are under the same license as IPython.' | |||||
102 | #***************************************************************************** |
|
102 | #***************************************************************************** | |
103 |
|
103 | |||
104 | import bdb |
|
104 | import bdb | |
105 | import functools |
|
|||
106 | import inspect |
|
105 | import inspect | |
107 | import linecache |
|
106 | import linecache | |
108 | import sys |
|
107 | import sys | |
@@ -163,94 +162,6 b' def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None):' | |||||
163 | print('Exiting Debugger.') |
|
162 | print('Exiting Debugger.') | |
164 |
|
163 | |||
165 |
|
164 | |||
166 | class Tracer(object): |
|
|||
167 | """ |
|
|||
168 | DEPRECATED |
|
|||
169 |
|
||||
170 | Class for local debugging, similar to pdb.set_trace. |
|
|||
171 |
|
||||
172 | Instances of this class, when called, behave like pdb.set_trace, but |
|
|||
173 | providing IPython's enhanced capabilities. |
|
|||
174 |
|
||||
175 | This is implemented as a class which must be initialized in your own code |
|
|||
176 | and not as a standalone function because we need to detect at runtime |
|
|||
177 | whether IPython is already active or not. That detection is done in the |
|
|||
178 | constructor, ensuring that this code plays nicely with a running IPython, |
|
|||
179 | while functioning acceptably (though with limitations) if outside of it. |
|
|||
180 | """ |
|
|||
181 |
|
||||
182 | def __init__(self, colors=None): |
|
|||
183 | """ |
|
|||
184 | DEPRECATED |
|
|||
185 |
|
||||
186 | Create a local debugger instance. |
|
|||
187 |
|
||||
188 | Parameters |
|
|||
189 | ---------- |
|
|||
190 | colors : str, optional |
|
|||
191 | The name of the color scheme to use, it must be one of IPython's |
|
|||
192 | valid color schemes. If not given, the function will default to |
|
|||
193 | the current IPython scheme when running inside IPython, and to |
|
|||
194 | 'NoColor' otherwise. |
|
|||
195 |
|
||||
196 | Examples |
|
|||
197 | -------- |
|
|||
198 | :: |
|
|||
199 |
|
||||
200 | from IPython.core.debugger import Tracer; debug_here = Tracer() |
|
|||
201 |
|
||||
202 | Later in your code:: |
|
|||
203 |
|
||||
204 | debug_here() # -> will open up the debugger at that point. |
|
|||
205 |
|
||||
206 | Once the debugger activates, you can use all of its regular commands to |
|
|||
207 | step through code, set breakpoints, etc. See the pdb documentation |
|
|||
208 | from the Python standard library for usage details. |
|
|||
209 | """ |
|
|||
210 | warnings.warn("`Tracer` is deprecated since version 5.1, directly use " |
|
|||
211 | "`IPython.core.debugger.Pdb.set_trace()`", |
|
|||
212 | DeprecationWarning, stacklevel=2) |
|
|||
213 |
|
||||
214 | ip = get_ipython() |
|
|||
215 | if ip is None: |
|
|||
216 | # Outside of ipython, we set our own exception hook manually |
|
|||
217 | sys.excepthook = functools.partial(BdbQuit_excepthook, |
|
|||
218 | excepthook=sys.excepthook) |
|
|||
219 | def_colors = 'NoColor' |
|
|||
220 | else: |
|
|||
221 | # In ipython, we use its custom exception handler mechanism |
|
|||
222 | def_colors = ip.colors |
|
|||
223 | ip.set_custom_exc((bdb.BdbQuit,), BdbQuit_IPython_excepthook) |
|
|||
224 |
|
||||
225 | if colors is None: |
|
|||
226 | colors = def_colors |
|
|||
227 |
|
||||
228 | # The stdlib debugger internally uses a modified repr from the `repr` |
|
|||
229 | # module, that limits the length of printed strings to a hardcoded |
|
|||
230 | # limit of 30 characters. That much trimming is too aggressive, let's |
|
|||
231 | # at least raise that limit to 80 chars, which should be enough for |
|
|||
232 | # most interactive uses. |
|
|||
233 | try: |
|
|||
234 | from reprlib import aRepr |
|
|||
235 | aRepr.maxstring = 80 |
|
|||
236 | except: |
|
|||
237 | # This is only a user-facing convenience, so any error we encounter |
|
|||
238 | # here can be warned about but can be otherwise ignored. These |
|
|||
239 | # printouts will tell us about problems if this API changes |
|
|||
240 | import traceback |
|
|||
241 | traceback.print_exc() |
|
|||
242 |
|
||||
243 | self.debugger = Pdb(colors) |
|
|||
244 |
|
||||
245 | def __call__(self): |
|
|||
246 | """Starts an interactive debugger at the point where called. |
|
|||
247 |
|
||||
248 | This is similar to the pdb.set_trace() function from the std lib, but |
|
|||
249 | using IPython's enhanced debugger.""" |
|
|||
250 |
|
||||
251 | self.debugger.set_trace(sys._getframe().f_back) |
|
|||
252 |
|
||||
253 |
|
||||
254 | RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+') |
|
165 | RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+') | |
255 |
|
166 | |||
256 |
|
167 | |||
@@ -290,14 +201,11 b' class Pdb(OldPdb):' | |||||
290 | "debuggerskip": True, |
|
201 | "debuggerskip": True, | |
291 | } |
|
202 | } | |
292 |
|
203 | |||
293 | def __init__(self, color_scheme=None, completekey=None, |
|
204 | def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwargs): | |
294 | stdin=None, stdout=None, context=5, **kwargs): |
|
|||
295 | """Create a new IPython debugger. |
|
205 | """Create a new IPython debugger. | |
296 |
|
206 | |||
297 | Parameters |
|
207 | Parameters | |
298 | ---------- |
|
208 | ---------- | |
299 | color_scheme : default None |
|
|||
300 | Deprecated, do not use. |
|
|||
301 | completekey : default None |
|
209 | completekey : default None | |
302 | Passed to pdb.Pdb. |
|
210 | Passed to pdb.Pdb. | |
303 | stdin : default None |
|
211 | stdin : default None | |
@@ -340,12 +248,8 b' class Pdb(OldPdb):' | |||||
340 | # the debugger was entered. See also #9941. |
|
248 | # the debugger was entered. See also #9941. | |
341 | sys.modules["__main__"] = save_main |
|
249 | sys.modules["__main__"] = save_main | |
342 |
|
250 | |||
343 | if color_scheme is not None: |
|
251 | ||
344 | warnings.warn( |
|
252 | color_scheme = self.shell.colors | |
345 | "The `color_scheme` argument is deprecated since version 5.1", |
|
|||
346 | DeprecationWarning, stacklevel=2) |
|
|||
347 | else: |
|
|||
348 | color_scheme = self.shell.colors |
|
|||
349 |
|
253 | |||
350 | self.aliases = {} |
|
254 | self.aliases = {} | |
351 |
|
255 |
@@ -85,12 +85,6 b' import IPython.core.hooks' | |||||
85 | from typing import List as ListType, Tuple, Optional, Callable |
|
85 | from typing import List as ListType, Tuple, Optional, Callable | |
86 | from ast import stmt |
|
86 | from ast import stmt | |
87 |
|
87 | |||
88 |
|
||||
89 | # NoOpContext is deprecated, but ipykernel imports it from here. |
|
|||
90 | # See https://github.com/ipython/ipykernel/issues/157 |
|
|||
91 | # (2016, let's try to remove than in IPython 8.0) |
|
|||
92 | from IPython.utils.contexts import NoOpContext |
|
|||
93 |
|
||||
94 | sphinxify: Optional[Callable] |
|
88 | sphinxify: Optional[Callable] | |
95 |
|
89 | |||
96 | try: |
|
90 | try: |
@@ -7,13 +7,8 b'' | |||||
7 | import bdb |
|
7 | import bdb | |
8 | import builtins |
|
8 | import builtins | |
9 | import os |
|
9 | import os | |
10 | import signal |
|
|||
11 | import subprocess |
|
|||
12 | import sys |
|
10 | import sys | |
13 | import time |
|
|||
14 | import warnings |
|
|||
15 |
|
11 | |||
16 | from subprocess import PIPE, CalledProcessError, check_output |
|
|||
17 | from tempfile import NamedTemporaryFile |
|
12 | from tempfile import NamedTemporaryFile | |
18 | from textwrap import dedent |
|
13 | from textwrap import dedent | |
19 | from unittest.mock import patch |
|
14 | from unittest.mock import patch | |
@@ -58,20 +53,6 b' class PdbTestInput(object):' | |||||
58 | # Tests |
|
53 | # Tests | |
59 | #----------------------------------------------------------------------------- |
|
54 | #----------------------------------------------------------------------------- | |
60 |
|
55 | |||
61 | def test_longer_repr(): |
|
|||
62 | from reprlib import repr as trepr |
|
|||
63 |
|
||||
64 | a = '1234567890'* 7 |
|
|||
65 | ar = "'1234567890123456789012345678901234567890123456789012345678901234567890'" |
|
|||
66 | a_trunc = "'123456789012...8901234567890'" |
|
|||
67 | assert trepr(a) == a_trunc |
|
|||
68 | # The creation of our tracer modifies the repr module's repr function |
|
|||
69 | # in-place, since that global is used directly by the stdlib's pdb module. |
|
|||
70 | with warnings.catch_warnings(): |
|
|||
71 | warnings.simplefilter('ignore', DeprecationWarning) |
|
|||
72 | debugger.Tracer() |
|
|||
73 | assert trepr(a) == ar |
|
|||
74 |
|
||||
75 | def test_ipdb_magics(): |
|
56 | def test_ipdb_magics(): | |
76 | '''Test calling some IPython magics from ipdb. |
|
57 | '''Test calling some IPython magics from ipdb. | |
77 |
|
58 |
@@ -58,17 +58,3 b' class preserve_keys(object):' | |||||
58 | for k in self.to_delete: |
|
58 | for k in self.to_delete: | |
59 | d.pop(k, None) |
|
59 | d.pop(k, None) | |
60 | d.update(self.to_update) |
|
60 | d.update(self.to_update) | |
61 |
|
||||
62 |
|
||||
63 | class NoOpContext(object): |
|
|||
64 | """ |
|
|||
65 | Deprecated |
|
|||
66 |
|
||||
67 | Context manager that does nothing.""" |
|
|||
68 |
|
||||
69 | def __init__(self): |
|
|||
70 | warnings.warn("""NoOpContext is deprecated since IPython 5.0 """, |
|
|||
71 | DeprecationWarning, stacklevel=2) |
|
|||
72 |
|
||||
73 | def __enter__(self): pass |
|
|||
74 | def __exit__(self, type, value, traceback): pass |
|
General Comments 0
You need to be logged in to leave comments.
Login now