Show More
@@ -49,7 +49,7 b' from .core.error import TryNext' | |||
|
49 | 49 | from .core.interactiveshell import InteractiveShell |
|
50 | 50 | from .testing import test |
|
51 | 51 | from .utils.sysinfo import sys_info |
|
52 |
from .utils.frame import |
|
|
52 | from .utils.frame import extract_module_locals_above | |
|
53 | 53 | |
|
54 | 54 | # Release data |
|
55 | 55 | __author__ = '' |
@@ -60,7 +60,7 b' __version__ = release.version' | |||
|
60 | 60 | |
|
61 | 61 | def embed_kernel(module=None, local_ns=None): |
|
62 | 62 | """Call this to embed an IPython kernel at the current point in your program. """ |
|
63 |
(caller_module, caller_locals) = |
|
|
63 | (caller_module, caller_locals) = extract_module_locals_above() | |
|
64 | 64 | if module is None: |
|
65 | 65 | module = caller_module |
|
66 | 66 | if local_ns is None: |
@@ -85,10 +85,16 b" def debugx(expr,pre_msg=''):" | |||
|
85 | 85 | # deactivate it by uncommenting the following line, which makes it a no-op |
|
86 | 86 | #def debugx(expr,pre_msg=''): pass |
|
87 | 87 | |
|
88 |
def |
|
|
89 | """Returns (module, locals) of the caller""" | |
|
90 |
|
|
|
91 |
global_ns = |
|
|
88 | def extract_module_locals(depth=0): | |
|
89 | """Returns (module, locals) of the funciton `depth` frames away from the caller""" | |
|
90 | f = sys._getframe(depth + 1) | |
|
91 | global_ns = f.f_globals | |
|
92 | 92 | module = sys.modules[global_ns['__name__']] |
|
93 |
return (module, |
|
|
93 | return (module, f.f_locals) | |
|
94 | ||
|
95 | def extract_module_locals_above(): | |
|
96 | """Returns (module, locals) of the funciton calling the caller. | |
|
97 | Like extract_module_locals() with a specified depth of 1.""" | |
|
98 | # we're one frame away from the target, the function we call would be two frames away | |
|
99 | return extract_module_locals(1 + 1) | |
|
94 | 100 |
General Comments 0
You need to be logged in to leave comments.
Login now