Show More
@@ -191,64 +191,6 b' class SeparateStr(Str):' | |||||
191 | return super(SeparateStr, self).validate(obj, value) |
|
191 | return super(SeparateStr, self).validate(obj, value) | |
192 |
|
192 | |||
193 |
|
193 | |||
194 | def make_user_namespaces(user_ns=None, user_global_ns=None): |
|
|||
195 | """Return a valid local and global user interactive namespaces. |
|
|||
196 |
|
||||
197 | This builds a dict with the minimal information needed to operate as a |
|
|||
198 | valid IPython user namespace, which you can pass to the various |
|
|||
199 | embedding classes in ipython. The default implementation returns the |
|
|||
200 | same dict for both the locals and the globals to allow functions to |
|
|||
201 | refer to variables in the namespace. Customized implementations can |
|
|||
202 | return different dicts. The locals dictionary can actually be anything |
|
|||
203 | following the basic mapping protocol of a dict, but the globals dict |
|
|||
204 | must be a true dict, not even a subclass. It is recommended that any |
|
|||
205 | custom object for the locals namespace synchronize with the globals |
|
|||
206 | dict somehow. |
|
|||
207 |
|
||||
208 | Raises TypeError if the provided globals namespace is not a true dict. |
|
|||
209 |
|
||||
210 | Parameters |
|
|||
211 | ---------- |
|
|||
212 | user_ns : dict-like, optional |
|
|||
213 | The current user namespace. The items in this namespace should |
|
|||
214 | be included in the output. If None, an appropriate blank |
|
|||
215 | namespace should be created. |
|
|||
216 | user_global_ns : dict, optional |
|
|||
217 | The current user global namespace. The items in this namespace |
|
|||
218 | should be included in the output. If None, an appropriate |
|
|||
219 | blank namespace should be created. |
|
|||
220 |
|
||||
221 | Returns |
|
|||
222 | ------- |
|
|||
223 | A pair of dictionary-like object to be used as the local namespace |
|
|||
224 | of the interpreter and a dict to be used as the global namespace. |
|
|||
225 | """ |
|
|||
226 |
|
||||
227 |
|
||||
228 | # We must ensure that __builtin__ (without the final 's') is always |
|
|||
229 | # available and pointing to the __builtin__ *module*. For more details: |
|
|||
230 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html |
|
|||
231 |
|
||||
232 | if user_ns is None: |
|
|||
233 | # Set __name__ to __main__ to better match the behavior of the |
|
|||
234 | # normal interpreter. |
|
|||
235 | user_ns = {'__name__' :'__main__', |
|
|||
236 | '__builtin__' : __builtin__, |
|
|||
237 | '__builtins__' : __builtin__, |
|
|||
238 | } |
|
|||
239 | else: |
|
|||
240 | user_ns.setdefault('__name__','__main__') |
|
|||
241 | user_ns.setdefault('__builtin__',__builtin__) |
|
|||
242 | user_ns.setdefault('__builtins__',__builtin__) |
|
|||
243 |
|
||||
244 | if user_global_ns is None: |
|
|||
245 | user_global_ns = user_ns |
|
|||
246 | if type(user_global_ns) is not dict: |
|
|||
247 | raise TypeError("user_global_ns must be a true dict; got %r" |
|
|||
248 | % type(user_global_ns)) |
|
|||
249 |
|
||||
250 | return user_ns, user_global_ns |
|
|||
251 |
|
||||
252 | #----------------------------------------------------------------------------- |
|
194 | #----------------------------------------------------------------------------- | |
253 | # Main IPython class |
|
195 | # Main IPython class | |
254 | #----------------------------------------------------------------------------- |
|
196 | #----------------------------------------------------------------------------- | |
@@ -880,7 +822,7 b' class InteractiveShell(Component, Magic):' | |||||
880 | # These routines return properly built dicts as needed by the rest of |
|
822 | # These routines return properly built dicts as needed by the rest of | |
881 | # the code, and can also be used by extension writers to generate |
|
823 | # the code, and can also be used by extension writers to generate | |
882 | # properly initialized namespaces. |
|
824 | # properly initialized namespaces. | |
883 | user_ns, user_global_ns = make_user_namespaces(user_ns, user_global_ns) |
|
825 | user_ns, user_global_ns = self.make_user_namespaces(user_ns, user_global_ns) | |
884 |
|
826 | |||
885 | # Assign namespaces |
|
827 | # Assign namespaces | |
886 | # This is the namespace where all normal user variables live |
|
828 | # This is the namespace where all normal user variables live | |
@@ -940,6 +882,64 b' class InteractiveShell(Component, Magic):' | |||||
940 | self.ns_refs_table = [ user_ns, user_global_ns, self.user_config_ns, |
|
882 | self.ns_refs_table = [ user_ns, user_global_ns, self.user_config_ns, | |
941 | self.internal_ns, self._main_ns_cache ] |
|
883 | self.internal_ns, self._main_ns_cache ] | |
942 |
|
884 | |||
|
885 | def make_user_namespaces(self, user_ns=None, user_global_ns=None): | |||
|
886 | """Return a valid local and global user interactive namespaces. | |||
|
887 | ||||
|
888 | This builds a dict with the minimal information needed to operate as a | |||
|
889 | valid IPython user namespace, which you can pass to the various | |||
|
890 | embedding classes in ipython. The default implementation returns the | |||
|
891 | same dict for both the locals and the globals to allow functions to | |||
|
892 | refer to variables in the namespace. Customized implementations can | |||
|
893 | return different dicts. The locals dictionary can actually be anything | |||
|
894 | following the basic mapping protocol of a dict, but the globals dict | |||
|
895 | must be a true dict, not even a subclass. It is recommended that any | |||
|
896 | custom object for the locals namespace synchronize with the globals | |||
|
897 | dict somehow. | |||
|
898 | ||||
|
899 | Raises TypeError if the provided globals namespace is not a true dict. | |||
|
900 | ||||
|
901 | Parameters | |||
|
902 | ---------- | |||
|
903 | user_ns : dict-like, optional | |||
|
904 | The current user namespace. The items in this namespace should | |||
|
905 | be included in the output. If None, an appropriate blank | |||
|
906 | namespace should be created. | |||
|
907 | user_global_ns : dict, optional | |||
|
908 | The current user global namespace. The items in this namespace | |||
|
909 | should be included in the output. If None, an appropriate | |||
|
910 | blank namespace should be created. | |||
|
911 | ||||
|
912 | Returns | |||
|
913 | ------- | |||
|
914 | A pair of dictionary-like object to be used as the local namespace | |||
|
915 | of the interpreter and a dict to be used as the global namespace. | |||
|
916 | """ | |||
|
917 | ||||
|
918 | ||||
|
919 | # We must ensure that __builtin__ (without the final 's') is always | |||
|
920 | # available and pointing to the __builtin__ *module*. For more details: | |||
|
921 | # http://mail.python.org/pipermail/python-dev/2001-April/014068.html | |||
|
922 | ||||
|
923 | if user_ns is None: | |||
|
924 | # Set __name__ to __main__ to better match the behavior of the | |||
|
925 | # normal interpreter. | |||
|
926 | user_ns = {'__name__' :'__main__', | |||
|
927 | '__builtin__' : __builtin__, | |||
|
928 | '__builtins__' : __builtin__, | |||
|
929 | } | |||
|
930 | else: | |||
|
931 | user_ns.setdefault('__name__','__main__') | |||
|
932 | user_ns.setdefault('__builtin__',__builtin__) | |||
|
933 | user_ns.setdefault('__builtins__',__builtin__) | |||
|
934 | ||||
|
935 | if user_global_ns is None: | |||
|
936 | user_global_ns = user_ns | |||
|
937 | if type(user_global_ns) is not dict: | |||
|
938 | raise TypeError("user_global_ns must be a true dict; got %r" | |||
|
939 | % type(user_global_ns)) | |||
|
940 | ||||
|
941 | return user_ns, user_global_ns | |||
|
942 | ||||
943 | def init_sys_modules(self): |
|
943 | def init_sys_modules(self): | |
944 | # We need to insert into sys.modules something that looks like a |
|
944 | # We need to insert into sys.modules something that looks like a | |
945 | # module but which accesses the IPython namespace, for shelve and |
|
945 | # module but which accesses the IPython namespace, for shelve and |
@@ -128,9 +128,8 b' class PrettyResultDisplay(Component):' | |||||
128 | #----------------------------------------------------------------------------- |
|
128 | #----------------------------------------------------------------------------- | |
129 |
|
129 | |||
130 |
|
130 | |||
131 |
def load_ipython_extension(ip |
|
131 | def load_ipython_extension(ip): | |
132 | """Load the extension in IPython as a hook.""" |
|
132 | """Load the extension in IPython as a hook.""" | |
133 | if ip is None: ip = get_ipython() |
|
|||
134 | global _loaded |
|
133 | global _loaded | |
135 | if not _loaded: |
|
134 | if not _loaded: | |
136 | prd = PrettyResultDisplay(ip, name='pretty_result_display') |
|
135 | prd = PrettyResultDisplay(ip, name='pretty_result_display') |
@@ -39,9 +39,10 b' def common_prefix(strings):' | |||||
39 |
|
39 | |||
40 | return prefix |
|
40 | return prefix | |
41 |
|
41 | |||
42 |
#----------------------------------------------------------------------------- |
|
42 | #----------------------------------------------------------------------------- | |
43 | # Base class for the line-oriented front ends |
|
43 | # Base class for the line-oriented front ends | |
44 |
#----------------------------------------------------------------------------- |
|
44 | #----------------------------------------------------------------------------- | |
|
45 | ||||
45 | class LineFrontEndBase(FrontEndBase): |
|
46 | class LineFrontEndBase(FrontEndBase): | |
46 | """ Concrete implementation of the FrontEndBase class. This is meant |
|
47 | """ Concrete implementation of the FrontEndBase class. This is meant | |
47 | to be the base class behind all the frontend that are line-oriented, |
|
48 | to be the base class behind all the frontend that are line-oriented, |
@@ -26,7 +26,7 b' import os' | |||||
26 | import re |
|
26 | import re | |
27 | import __builtin__ |
|
27 | import __builtin__ | |
28 |
|
28 | |||
29 |
from IPython.core.ip |
|
29 | from IPython.core.iplib import InteractiveShell | |
30 | from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap |
|
30 | from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap | |
31 |
|
31 | |||
32 | from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap |
|
32 | from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap | |
@@ -50,9 +50,10 b' def mk_system_call(system_call_function, command):' | |||||
50 | my_system_call.__doc__ = "Calls %s" % command |
|
50 | my_system_call.__doc__ = "Calls %s" % command | |
51 | return my_system_call |
|
51 | return my_system_call | |
52 |
|
52 | |||
53 |
#----------------------------------------------------------------------------- |
|
53 | #----------------------------------------------------------------------------- | |
54 | # Frontend class using ipython0 to do the prefiltering. |
|
54 | # Frontend class using ipython0 to do the prefiltering. | |
55 |
#----------------------------------------------------------------------------- |
|
55 | #----------------------------------------------------------------------------- | |
|
56 | ||||
56 | class PrefilterFrontEnd(LineFrontEndBase): |
|
57 | class PrefilterFrontEnd(LineFrontEndBase): | |
57 | """ Class that uses ipython0 to do prefilter the input, do the |
|
58 | """ Class that uses ipython0 to do prefilter the input, do the | |
58 | completion and the magics. |
|
59 | completion and the magics. | |
@@ -65,19 +66,13 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
65 |
|
66 | |||
66 | debug = False |
|
67 | debug = False | |
67 |
|
68 | |||
68 |
def __init__(self, ipython0=None, |
|
69 | def __init__(self, ipython0=None, *args, **kwargs): | |
69 | """ Parameters |
|
70 | """ Parameters | |
70 | ---------- |
|
71 | ---------- | |
71 |
|
72 | |||
72 | ipython0: an optional ipython0 instance to use for command |
|
73 | ipython0: an optional ipython0 instance to use for command | |
73 | prefiltering and completion. |
|
74 | prefiltering and completion. | |
74 |
|
||||
75 | argv : list, optional |
|
|||
76 | Used as the instance's argv value. If not given, [] is used. |
|
|||
77 | """ |
|
75 | """ | |
78 | if argv is None: |
|
|||
79 | argv = ['--no-banner'] |
|
|||
80 |
|
||||
81 | LineFrontEndBase.__init__(self, *args, **kwargs) |
|
76 | LineFrontEndBase.__init__(self, *args, **kwargs) | |
82 | self.shell.output_trap = RedirectorOutputTrap( |
|
77 | self.shell.output_trap = RedirectorOutputTrap( | |
83 | out_callback=self.write, |
|
78 | out_callback=self.write, | |
@@ -90,22 +85,19 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
90 | # Start the ipython0 instance: |
|
85 | # Start the ipython0 instance: | |
91 | self.save_output_hooks() |
|
86 | self.save_output_hooks() | |
92 | if ipython0 is None: |
|
87 | if ipython0 is None: | |
93 |
# Instanciate an IPython0 |
|
88 | # Instanciate an IPython0 InteractiveShell to be able to use the | |
94 | # prefiltering. |
|
89 | # prefiltering. | |
95 | # Suppress all key input, to avoid waiting |
|
90 | # Suppress all key input, to avoid waiting | |
96 | def my_rawinput(x=None): |
|
91 | def my_rawinput(x=None): | |
97 | return '\n' |
|
92 | return '\n' | |
98 | old_rawinput = __builtin__.raw_input |
|
93 | old_rawinput = __builtin__.raw_input | |
99 | __builtin__.raw_input = my_rawinput |
|
94 | __builtin__.raw_input = my_rawinput | |
100 |
ipython0 = I |
|
95 | ipython0 = InteractiveShell( | |
101 |
|
|
96 | parent=None, user_ns=self.shell.user_ns, | |
102 |
|
|
97 | user_global_ns=self.shell.user_global_ns | |
103 | ipython0.initialize() |
|
98 | ) | |
104 | __builtin__.raw_input = old_rawinput |
|
99 | __builtin__.raw_input = old_rawinput | |
105 | # XXX This will need to be updated as we refactor things, but for now, |
|
100 | self.ipython0 = ipython0 | |
106 | # the .shell attribute of the ipythonapp instance conforms to the old |
|
|||
107 | # api. |
|
|||
108 | self.ipython0 = ipython0.shell |
|
|||
109 | # Set the pager: |
|
101 | # Set the pager: | |
110 | self.ipython0.set_hook('show_in_pager', |
|
102 | self.ipython0.set_hook('show_in_pager', | |
111 | lambda s, string: self.write("\n" + string)) |
|
103 | lambda s, string: self.write("\n" + string)) |
@@ -1,14 +1,11 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
||||
3 | """This file contains unittests for the asyncfrontendbase module.""" |
|
2 | """This file contains unittests for the asyncfrontendbase module.""" | |
4 |
|
||||
5 | __docformat__ = "restructuredtext en" |
|
|||
6 |
|
3 | |||
7 | # Tell nose to skip this module |
|
4 | # Tell nose to skip this module | |
8 | __test__ = {} |
|
5 | __test__ = {} | |
9 |
|
6 | |||
10 | #--------------------------------------------------------------------------- |
|
7 | #--------------------------------------------------------------------------- | |
11 | # Copyright (C) 2008 The IPython Development Team |
|
8 | # Copyright (C) 2008-2009 The IPython Development Team | |
12 | # |
|
9 | # | |
13 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
14 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. |
@@ -21,7 +21,6 b' from nose.tools import assert_equal' | |||||
21 |
|
21 | |||
22 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd |
|
22 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd | |
23 | from IPython.testing.globalipapp import get_ipython |
|
23 | from IPython.testing.globalipapp import get_ipython | |
24 | from IPython.testing.tools import default_argv |
|
|||
25 |
|
24 | |||
26 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
27 | # Support utilities |
|
26 | # Support utilities | |
@@ -35,7 +34,7 b' class TestPrefilterFrontEnd(PrefilterFrontEnd):' | |||||
35 |
|
34 | |||
36 | def __init__(self): |
|
35 | def __init__(self): | |
37 | self.out = StringIO() |
|
36 | self.out = StringIO() | |
38 |
PrefilterFrontEnd.__init__(self |
|
37 | PrefilterFrontEnd.__init__(self) | |
39 | # Some more code for isolation (yeah, crazy) |
|
38 | # Some more code for isolation (yeah, crazy) | |
40 | self._on_enter() |
|
39 | self._on_enter() | |
41 | self.out.flush() |
|
40 | self.out.flush() |
@@ -135,9 +135,10 b' else:' | |||||
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 |
|
137 | |||
138 |
#----------------------------------------------------------------------------- |
|
138 | #----------------------------------------------------------------------------- | |
139 | # The console widget class |
|
139 | # The console widget class | |
140 |
#----------------------------------------------------------------------------- |
|
140 | #----------------------------------------------------------------------------- | |
|
141 | ||||
141 | class ConsoleWidget(editwindow.EditWindow): |
|
142 | class ConsoleWidget(editwindow.EditWindow): | |
142 | """ Specialized styled text control view for console-like workflow. |
|
143 | """ Specialized styled text control view for console-like workflow. | |
143 |
|
144 |
@@ -47,7 +47,7 b' class IPythonXController(WxController):' | |||||
47 | self._input_state = 'subprocess' |
|
47 | self._input_state = 'subprocess' | |
48 | self.write('\n', refresh=False) |
|
48 | self.write('\n', refresh=False) | |
49 | self.capture_output() |
|
49 | self.capture_output() | |
50 |
self.ipython0. |
|
50 | self.ipython0.exit() | |
51 | self.release_output() |
|
51 | self.release_output() | |
52 | if not self.ipython0.exit_now: |
|
52 | if not self.ipython0.exit_now: | |
53 | wx.CallAfter(self.new_prompt, |
|
53 | wx.CallAfter(self.new_prompt, |
@@ -23,8 +23,7 b' import os' | |||||
23 | import locale |
|
23 | import locale | |
24 | from thread_ex import ThreadEx |
|
24 | from thread_ex import ThreadEx | |
25 |
|
25 | |||
26 | import IPython |
|
26 | from IPython.core import iplib | |
27 | from IPython.core import iplib, ipapp |
|
|||
28 | from IPython.utils.io import Term |
|
27 | from IPython.utils.io import Term | |
29 |
|
28 | |||
30 | ############################################################################## |
|
29 | ############################################################################## | |
@@ -88,12 +87,10 b' class NonBlockingIPShell(object):' | |||||
88 | via raise_exc() |
|
87 | via raise_exc() | |
89 | ''' |
|
88 | ''' | |
90 |
|
89 | |||
91 |
def __init__(self |
|
90 | def __init__(self, user_ns={}, user_global_ns=None, | |
92 | cin=None, cout=None, cerr=None, |
|
91 | cin=None, cout=None, cerr=None, | |
93 | ask_exit_handler=None): |
|
92 | ask_exit_handler=None): | |
94 | ''' |
|
93 | ''' | |
95 | @param argv: Command line options for IPython |
|
|||
96 | @type argv: list |
|
|||
97 | @param user_ns: User namespace. |
|
94 | @param user_ns: User namespace. | |
98 | @type user_ns: dictionary |
|
95 | @type user_ns: dictionary | |
99 | @param user_global_ns: User global namespace. |
|
96 | @param user_global_ns: User global namespace. | |
@@ -111,9 +108,9 b' class NonBlockingIPShell(object):' | |||||
111 | ''' |
|
108 | ''' | |
112 | #ipython0 initialisation |
|
109 | #ipython0 initialisation | |
113 | self._IP = None |
|
110 | self._IP = None | |
114 |
self.init_ipython0( |
|
111 | self.init_ipython0(user_ns, user_global_ns, | |
115 | cin, cout, cerr, |
|
112 | cin, cout, cerr, | |
116 | ask_exit_handler) |
|
113 | ask_exit_handler) | |
117 |
|
114 | |||
118 | #vars used by _execute |
|
115 | #vars used by _execute | |
119 | self._iter_more = 0 |
|
116 | self._iter_more = 0 | |
@@ -131,7 +128,7 b' class NonBlockingIPShell(object):' | |||||
131 | self._help_text = None |
|
128 | self._help_text = None | |
132 | self._add_button = None |
|
129 | self._add_button = None | |
133 |
|
130 | |||
134 |
def init_ipython0(self |
|
131 | def init_ipython0(self, user_ns={}, user_global_ns=None, | |
135 | cin=None, cout=None, cerr=None, |
|
132 | cin=None, cout=None, cerr=None, | |
136 | ask_exit_handler=None): |
|
133 | ask_exit_handler=None): | |
137 | ''' Initialize an ipython0 instance ''' |
|
134 | ''' Initialize an ipython0 instance ''' | |
@@ -151,17 +148,12 b' class NonBlockingIPShell(object):' | |||||
151 |
|
148 | |||
152 | #Hack to save sys.displayhook, because ipython seems to overwrite it... |
|
149 | #Hack to save sys.displayhook, because ipython seems to overwrite it... | |
153 | self.sys_displayhook_ori = sys.displayhook |
|
150 | self.sys_displayhook_ori = sys.displayhook | |
154 |
|
151 | ipython0 = iplib.InteractiveShell( | ||
155 | ipython0 = ipapp.IPythonApp(argv,user_ns=user_ns, |
|
152 | parent=None, config=None, | |
156 | user_global_ns=user_global_ns) |
|
153 | user_ns=user_ns, | |
157 | ipython0.initialize() |
|
154 | user_global_ns=user_global_ns | |
158 | self._IP = ipython0.shell |
|
155 | ) | |
159 |
|
156 | self._IP = ipython0 | ||
160 | ## self._IP = IPython.shell.make_IPython( |
|
|||
161 | ## argv,user_ns=user_ns, |
|
|||
162 | ## user_global_ns=user_global_ns, |
|
|||
163 | ## embedded=True, |
|
|||
164 | ## shell_class=IPython.shell.InteractiveShell) |
|
|||
165 |
|
157 | |||
166 | #we save ipython0 displayhook and we restore sys.displayhook |
|
158 | #we save ipython0 displayhook and we restore sys.displayhook | |
167 | self.displayhook = sys.displayhook |
|
159 | self.displayhook = sys.displayhook | |
@@ -185,12 +177,10 b' class NonBlockingIPShell(object):' | |||||
185 | #we replace the help command |
|
177 | #we replace the help command | |
186 | self._IP.user_ns['help'] = _Helper(self._pager_help) |
|
178 | self._IP.user_ns['help'] = _Helper(self._pager_help) | |
187 |
|
179 | |||
188 | #we disable cpase magic... until we found a way to use it properly. |
|
180 | #we disable cpaste magic... until we found a way to use it properly. | |
189 | from IPython.core import ipapi |
|
|||
190 | ip = ipapi.get() |
|
|||
191 | def bypass_magic(self, arg): |
|
181 | def bypass_magic(self, arg): | |
192 | print '%this magic is currently disabled.' |
|
182 | print '%this magic is currently disabled.' | |
193 | ip.define_magic('cpaste', bypass_magic) |
|
183 | ipython0.define_magic('cpaste', bypass_magic) | |
194 |
|
184 | |||
195 | import __builtin__ |
|
185 | import __builtin__ | |
196 | __builtin__.raw_input = self._raw_input |
|
186 | __builtin__.raw_input = self._raw_input |
@@ -11,6 +11,7 b' __author__ = "Laurent Dufrechou"' | |||||
11 | __email__ = "laurent.dufrechou _at_ gmail.com" |
|
11 | __email__ = "laurent.dufrechou _at_ gmail.com" | |
12 | __license__ = "BSD" |
|
12 | __license__ = "BSD" | |
13 | #----------------------------------------- |
|
13 | #----------------------------------------- | |
|
14 | ||||
14 | class IPythonHistoryPanel(wx.Panel): |
|
15 | class IPythonHistoryPanel(wx.Panel): | |
15 |
|
16 | |||
16 | def __init__(self, parent,flt_empty=True, |
|
17 | def __init__(self, parent,flt_empty=True, |
@@ -361,8 +361,11 b' class IPClusterApp(ApplicationWithClusterDir):' | |||||
361 | log.msg('Unexpected error in ipcluster:') |
|
361 | log.msg('Unexpected error in ipcluster:') | |
362 | log.msg(r.getTraceback()) |
|
362 | log.msg(r.getTraceback()) | |
363 | log.msg("IPython cluster: stopping") |
|
363 | log.msg("IPython cluster: stopping") | |
364 | self.stop_engines() |
|
364 | # These return deferreds. We are not doing anything with them | |
365 | self.stop_controller() |
|
365 | # but we are holding refs to them as a reminder that they | |
|
366 | # do return deferreds. | |||
|
367 | d1 = self.stop_engines() | |||
|
368 | d2 = self.stop_controller() | |||
366 | # Wait a few seconds to let things shut down. |
|
369 | # Wait a few seconds to let things shut down. | |
367 | reactor.callLater(4.0, reactor.stop) |
|
370 | reactor.callLater(4.0, reactor.stop) | |
368 |
|
371 |
@@ -1,15 +1,18 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | A module to change reload() so that it acts recursively. |
|
3 | A module to change reload() so that it acts recursively. | |
4 | To enable it type: |
|
4 | To enable it type:: | |
5 | >>> import __builtin__, deepreload |
|
|||
6 | >>> __builtin__.reload = deepreload.reload |
|
|||
7 |
|
5 | |||
8 | You can then disable it with: |
|
6 | import __builtin__, deepreload | |
9 |
|
|
7 | __builtin__.reload = deepreload.reload | |
|
8 | ||||
|
9 | You can then disable it with:: | |||
|
10 | ||||
|
11 | __builtin__.reload = deepreload.original_reload | |||
10 |
|
12 | |||
11 | Alternatively, you can add a dreload builtin alongside normal reload with: |
|
13 | Alternatively, you can add a dreload builtin alongside normal reload with:: | |
12 | >>> __builtin__.dreload = deepreload.reload |
|
14 | ||
|
15 | __builtin__.dreload = deepreload.reload | |||
13 |
|
16 | |||
14 | This code is almost entirely based on knee.py from the standard library. |
|
17 | This code is almost entirely based on knee.py from the standard library. | |
15 | """ |
|
18 | """ |
@@ -97,24 +97,25 b' class ipnsdict(dict):' | |||||
97 | # correct for that ourselves, to ensure consitency with the 'real' |
|
97 | # correct for that ourselves, to ensure consitency with the 'real' | |
98 | # ipython. |
|
98 | # ipython. | |
99 | self['__builtins__'] = __builtin__ |
|
99 | self['__builtins__'] = __builtin__ | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | def get_ipython(): |
|
102 | def get_ipython(): | |
103 | # This will get replaced by the real thing once we start IPython below |
|
103 | # This will get replaced by the real thing once we start IPython below | |
104 | return start_ipython() |
|
104 | return start_ipython() | |
105 |
|
105 | |||
|
106 | ||||
106 | def start_ipython(): |
|
107 | def start_ipython(): | |
107 | """Start a global IPython shell, which we need for IPython-specific syntax. |
|
108 | """Start a global IPython shell, which we need for IPython-specific syntax. | |
108 | """ |
|
109 | """ | |
109 | global get_ipython |
|
110 | global get_ipython | |
110 |
|
111 | |||
111 | # This function should only ever run once! |
|
112 | # This function should only ever run once! | |
112 | if hasattr(start_ipython,'already_called'): |
|
113 | if hasattr(start_ipython, 'already_called'): | |
113 | return |
|
114 | return | |
114 | start_ipython.already_called = True |
|
115 | start_ipython.already_called = True | |
115 |
|
116 | |||
116 | # Ok, first time we're called, go ahead |
|
117 | # Ok, first time we're called, go ahead | |
117 |
from IPython.core import |
|
118 | from IPython.core import iplib | |
118 |
|
119 | |||
119 | def xsys(cmd): |
|
120 | def xsys(cmd): | |
120 | """Execute a command and print its output. |
|
121 | """Execute a command and print its output. | |
@@ -132,26 +133,27 b' def start_ipython():' | |||||
132 | _main = sys.modules.get('__main__') |
|
133 | _main = sys.modules.get('__main__') | |
133 |
|
134 | |||
134 | # Create custom argv and namespaces for our IPython to be test-friendly |
|
135 | # Create custom argv and namespaces for our IPython to be test-friendly | |
135 |
|
|
136 | config = tools.default_config() | |
136 | user_ns, global_ns = iplib.make_user_namespaces(ipnsdict(), {}) |
|
137 | ||
137 |
|
||||
138 | # Create and initialize our test-friendly IPython instance. |
|
138 | # Create and initialize our test-friendly IPython instance. | |
139 | ip = ipapp.IPythonApp(argv, user_ns=user_ns, user_global_ns=global_ns) |
|
139 | shell = iplib.InteractiveShell( | |
140 | ip.initialize() |
|
140 | parent=None, config=config, | |
|
141 | user_ns=ipnsdict(), user_global_ns={} | |||
|
142 | ) | |||
141 |
|
143 | |||
142 | # A few more tweaks needed for playing nicely with doctests... |
|
144 | # A few more tweaks needed for playing nicely with doctests... | |
143 |
|
145 | |||
144 | # These traps are normally only active for interactive use, set them |
|
146 | # These traps are normally only active for interactive use, set them | |
145 | # permanently since we'll be mocking interactive sessions. |
|
147 | # permanently since we'll be mocking interactive sessions. | |
146 |
|
|
148 | shell.builtin_trap.set() | |
147 |
|
149 | |||
148 | # Set error printing to stdout so nose can doctest exceptions |
|
150 | # Set error printing to stdout so nose can doctest exceptions | |
149 |
|
|
151 | shell.InteractiveTB.out_stream = 'stdout' | |
150 |
|
152 | |||
151 | # Modify the IPython system call with one that uses getoutput, so that we |
|
153 | # Modify the IPython system call with one that uses getoutput, so that we | |
152 | # can capture subcommands and print them to Python's stdout, otherwise the |
|
154 | # can capture subcommands and print them to Python's stdout, otherwise the | |
153 | # doctest machinery would miss them. |
|
155 | # doctest machinery would miss them. | |
154 |
|
|
156 | shell.system = xsys | |
155 |
|
157 | |||
156 | # IPython is ready, now clean up some global state... |
|
158 | # IPython is ready, now clean up some global state... | |
157 |
|
159 | |||
@@ -164,7 +166,7 b' def start_ipython():' | |||||
164 | # So that ipython magics and aliases can be doctested (they work by making |
|
166 | # So that ipython magics and aliases can be doctested (they work by making | |
165 | # a call into a global _ip object). Also make the top-level get_ipython |
|
167 | # a call into a global _ip object). Also make the top-level get_ipython | |
166 | # now return this without recursively calling here again. |
|
168 | # now return this without recursively calling here again. | |
167 |
_ip = |
|
169 | _ip = shell | |
168 | get_ipython = _ip.get_ipython |
|
170 | get_ipython = _ip.get_ipython | |
169 | __builtin__._ip = _ip |
|
171 | __builtin__._ip = _ip | |
170 | __builtin__.get_ipython = get_ipython |
|
172 | __builtin__.get_ipython = get_ipython |
@@ -343,9 +343,9 b' def make_runners():' | |||||
343 |
|
343 | |||
344 | # And add twisted ones if conditions are met |
|
344 | # And add twisted ones if conditions are met | |
345 | if have['zope.interface'] and have['twisted'] and have['foolscap']: |
|
345 | if have['zope.interface'] and have['twisted'] and have['foolscap']: | |
346 | # Note that we list the kernel here, though the bulk of it is |
|
346 | # We only list IPython.kernel for testing using twisted.trial as | |
347 | # twisted-based, because nose picks up doctests that twisted doesn't. |
|
347 | # nose and twisted.trial have conflicts that make the testing system | |
348 | nose_pkg_names.append('kernel') |
|
348 | # unstable. | |
349 | trial_pkg_names.append('kernel') |
|
349 | trial_pkg_names.append('kernel') | |
350 |
|
350 | |||
351 | # For debugging this code, only load quick stuff |
|
351 | # For debugging this code, only load quick stuff |
@@ -41,6 +41,7 b' try:' | |||||
41 | except ImportError: |
|
41 | except ImportError: | |
42 | has_nose = False |
|
42 | has_nose = False | |
43 |
|
43 | |||
|
44 | from IPython.config.loader import Config | |||
44 | from IPython.utils.process import find_cmd, getoutputerror |
|
45 | from IPython.utils.process import find_cmd, getoutputerror | |
45 | from IPython.utils.text import list_strings |
|
46 | from IPython.utils.text import list_strings | |
46 | from IPython.utils.io import temp_pyfile |
|
47 | from IPython.utils.io import temp_pyfile | |
@@ -165,7 +166,16 b' def default_argv():' | |||||
165 | # Other defaults to minimize side effects on stdout |
|
166 | # Other defaults to minimize side effects on stdout | |
166 | '--colors=NoColor', '--no-term-title','--no-banner', |
|
167 | '--colors=NoColor', '--no-term-title','--no-banner', | |
167 | '--autocall=0'] |
|
168 | '--autocall=0'] | |
168 |
|
169 | |||
|
170 | ||||
|
171 | def default_config(): | |||
|
172 | """Return a config object with good defaults for testing.""" | |||
|
173 | config = Config() | |||
|
174 | config.InteractiveShell.colors = 'NoColor' | |||
|
175 | config.InteractiveShell.term_title = False, | |||
|
176 | config.InteractiveShell.autocall = 0 | |||
|
177 | return config | |||
|
178 | ||||
169 |
|
179 | |||
170 | def ipexec(fname, options=None): |
|
180 | def ipexec(fname, options=None): | |
171 | """Utility to call 'ipython filename'. |
|
181 | """Utility to call 'ipython filename'. |
@@ -249,9 +249,7 b' def get_ipython_dir():' | |||||
249 | and the adds .ipython to the end of the path. |
|
249 | and the adds .ipython to the end of the path. | |
250 | """ |
|
250 | """ | |
251 | ipdir_def = '.ipython' |
|
251 | ipdir_def = '.ipython' | |
252 | print get_home_dir |
|
|||
253 | home_dir = get_home_dir() |
|
252 | home_dir = get_home_dir() | |
254 | print home_dir |
|
|||
255 | #import pdb; pdb.set_trace() # dbg |
|
253 | #import pdb; pdb.set_trace() # dbg | |
256 | ipdir = os.environ.get( |
|
254 | ipdir = os.environ.get( | |
257 | 'IPYTHON_DIR', os.environ.get( |
|
255 | 'IPYTHON_DIR', os.environ.get( |
@@ -244,7 +244,7 b' and an example of ``# all-random``::' | |||||
244 |
|
244 | |||
245 | When writing docstrings, you can use the ``@skip_doctest`` decorator to |
|
245 | When writing docstrings, you can use the ``@skip_doctest`` decorator to | |
246 | indicate that a docstring should *not* be treated as a doctest at all. The |
|
246 | indicate that a docstring should *not* be treated as a doctest at all. The | |
247 | difference betwee ``# all-random`` and ``@skip_doctest`` is that the former |
|
247 | difference between ``# all-random`` and ``@skip_doctest`` is that the former | |
248 | executes the example but ignores output, while the latter doesn't execute any |
|
248 | executes the example but ignores output, while the latter doesn't execute any | |
249 | code. ``@skip_doctest`` should be used for docstrings whose examples are |
|
249 | code. ``@skip_doctest`` should be used for docstrings whose examples are | |
250 | purely informational. |
|
250 | purely informational. |
@@ -59,12 +59,9 b' Authors' | |||||
59 |
|
59 | |||
60 | # Stdlib |
|
60 | # Stdlib | |
61 | import cStringIO |
|
61 | import cStringIO | |
62 | import imp |
|
|||
63 | import os |
|
62 | import os | |
64 | import re |
|
63 | import re | |
65 | import shutil |
|
|||
66 | import sys |
|
64 | import sys | |
67 | import warnings |
|
|||
68 |
|
65 | |||
69 | # To keep compatibility with various python versions |
|
66 | # To keep compatibility with various python versions | |
70 | try: |
|
67 | try: | |
@@ -80,8 +77,8 b' from docutils.parsers.rst import directives' | |||||
80 | matplotlib.use('Agg') |
|
77 | matplotlib.use('Agg') | |
81 |
|
78 | |||
82 | # Our own |
|
79 | # Our own | |
83 |
from IPython import Config, I |
|
80 | from IPython import Config, InteractiveShell | |
84 |
from IPython.utils.io import Term |
|
81 | from IPython.utils.io import Term | |
85 |
|
82 | |||
86 | #----------------------------------------------------------------------------- |
|
83 | #----------------------------------------------------------------------------- | |
87 | # Globals |
|
84 | # Globals | |
@@ -222,15 +219,11 b' class EmbeddedSphinxShell(object):' | |||||
222 | config.InteractiveShell.autoindent = False |
|
219 | config.InteractiveShell.autoindent = False | |
223 | config.InteractiveShell.colors = 'NoColor' |
|
220 | config.InteractiveShell.colors = 'NoColor' | |
224 |
|
221 | |||
225 | # Merge global config which can be used to override. |
|
|||
226 | config._merge(CONFIG) |
|
|||
227 |
|
||||
228 | # Create and initialize ipython, but don't start its mainloop |
|
222 | # Create and initialize ipython, but don't start its mainloop | |
229 |
IP = I |
|
223 | IP = InteractiveShell(parent=None, config=config) | |
230 | IP.initialize() |
|
|||
231 |
|
224 | |||
232 | # Store a few parts of IPython we'll need. |
|
225 | # Store a few parts of IPython we'll need. | |
233 |
self.IP = IP |
|
226 | self.IP = IP | |
234 | self.user_ns = self.IP.user_ns |
|
227 | self.user_ns = self.IP.user_ns | |
235 | self.user_global_ns = self.IP.user_global_ns |
|
228 | self.user_global_ns = self.IP.user_global_ns | |
236 |
|
229 |
General Comments 0
You need to be logged in to leave comments.
Login now