Show More
@@ -30,6 +30,7 b' try:' | |||||
30 | from contextlib import nested |
|
30 | from contextlib import nested | |
31 | except: |
|
31 | except: | |
32 | from IPython.utils.nested_context import nested |
|
32 | from IPython.utils.nested_context import nested | |
|
33 | import warnings | |||
33 |
|
34 | |||
34 | from IPython.core import ultratb |
|
35 | from IPython.core import ultratb | |
35 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell |
|
36 | from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell | |
@@ -96,7 +97,7 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
96 | pass |
|
97 | pass | |
97 |
|
98 | |||
98 | def __call__(self, header='', local_ns=None, module=None, dummy=None, |
|
99 | def __call__(self, header='', local_ns=None, module=None, dummy=None, | |
99 | stack_depth=1): |
|
100 | stack_depth=1, global_ns=None): | |
100 | """Activate the interactive interpreter. |
|
101 | """Activate the interactive interpreter. | |
101 |
|
102 | |||
102 | __call__(self,header='',local_ns=None,global_ns,dummy=None) -> Start |
|
103 | __call__(self,header='',local_ns=None,global_ns,dummy=None) -> Start | |
@@ -140,7 +141,7 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
140 |
|
141 | |||
141 | # Call the embedding code with a stack depth of 1 so it can skip over |
|
142 | # Call the embedding code with a stack depth of 1 so it can skip over | |
142 | # our call and get the original caller's namespaces. |
|
143 | # our call and get the original caller's namespaces. | |
143 | self.mainloop(local_ns, module, stack_depth=stack_depth) |
|
144 | self.mainloop(local_ns, module, stack_depth=stack_depth, global_ns=global_ns) | |
144 |
|
145 | |||
145 | self.banner2 = self.old_banner2 |
|
146 | self.banner2 = self.old_banner2 | |
146 |
|
147 | |||
@@ -148,7 +149,7 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
148 | print self.exit_msg |
|
149 | print self.exit_msg | |
149 |
|
150 | |||
150 | def mainloop(self, local_ns=None, module=None, stack_depth=0, |
|
151 | def mainloop(self, local_ns=None, module=None, stack_depth=0, | |
151 | display_banner=None): |
|
152 | display_banner=None, global_ns=None): | |
152 | """Embeds IPython into a running python program. |
|
153 | """Embeds IPython into a running python program. | |
153 |
|
154 | |||
154 | Input: |
|
155 | Input: | |
@@ -170,6 +171,14 b' class InteractiveShellEmbed(TerminalInteractiveShell):' | |||||
170 | IPython itself (via %run), but some funny things will happen (a few |
|
171 | IPython itself (via %run), but some funny things will happen (a few | |
171 | globals get overwritten). In the future this will be cleaned up, as |
|
172 | globals get overwritten). In the future this will be cleaned up, as | |
172 | there is no fundamental reason why it can't work perfectly.""" |
|
173 | there is no fundamental reason why it can't work perfectly.""" | |
|
174 | ||||
|
175 | if (global_ns is not None) and (module is None): | |||
|
176 | class DummyMod(object): | |||
|
177 | """A dummy module object for embedded IPython.""" | |||
|
178 | pass | |||
|
179 | warnings.warn("global_ns is deprecated, use module instead.", DeprecationWarning) | |||
|
180 | module = DummyMod() | |||
|
181 | module.__dict__ = global_ns | |||
173 |
|
182 | |||
174 | # Get locals and globals from caller |
|
183 | # Get locals and globals from caller | |
175 | if (local_ns is None or module is None) and self.default_user_namespaces: |
|
184 | if (local_ns is None or module is None) and self.default_user_namespaces: |
General Comments 0
You need to be logged in to leave comments.
Login now