Show More
@@ -191,64 +191,6 b' class SeparateStr(Str):' | |||
|
191 | 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 | 195 | # Main IPython class |
|
254 | 196 | #----------------------------------------------------------------------------- |
@@ -880,7 +822,7 b' class InteractiveShell(Component, Magic):' | |||
|
880 | 822 | # These routines return properly built dicts as needed by the rest of |
|
881 | 823 | # the code, and can also be used by extension writers to generate |
|
882 | 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 | 827 | # Assign namespaces |
|
886 | 828 | # This is the namespace where all normal user variables live |
@@ -940,6 +882,64 b' class InteractiveShell(Component, Magic):' | |||
|
940 | 882 | self.ns_refs_table = [ user_ns, user_global_ns, self.user_config_ns, |
|
941 | 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 | 943 | def init_sys_modules(self): |
|
944 | 944 | # We need to insert into sys.modules something that looks like a |
|
945 | 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 | 132 | """Load the extension in IPython as a hook.""" |
|
133 | if ip is None: ip = get_ipython() | |
|
134 | 133 | global _loaded |
|
135 | 134 | if not _loaded: |
|
136 | 135 | prd = PrettyResultDisplay(ip, name='pretty_result_display') |
@@ -39,9 +39,10 b' def common_prefix(strings):' | |||
|
39 | 39 | |
|
40 | 40 | return prefix |
|
41 | 41 | |
|
42 |
#----------------------------------------------------------------------------- |
|
|
42 | #----------------------------------------------------------------------------- | |
|
43 | 43 | # Base class for the line-oriented front ends |
|
44 |
#----------------------------------------------------------------------------- |
|
|
44 | #----------------------------------------------------------------------------- | |
|
45 | ||
|
45 | 46 | class LineFrontEndBase(FrontEndBase): |
|
46 | 47 | """ Concrete implementation of the FrontEndBase class. This is meant |
|
47 | 48 | to be the base class behind all the frontend that are line-oriented, |
@@ -26,7 +26,7 b' import os' | |||
|
26 | 26 | import re |
|
27 | 27 | import __builtin__ |
|
28 | 28 | |
|
29 |
from IPython.core.ip |
|
|
29 | from IPython.core.iplib import InteractiveShell | |
|
30 | 30 | from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap |
|
31 | 31 | |
|
32 | 32 | from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap |
@@ -50,9 +50,10 b' def mk_system_call(system_call_function, command):' | |||
|
50 | 50 | my_system_call.__doc__ = "Calls %s" % command |
|
51 | 51 | return my_system_call |
|
52 | 52 | |
|
53 |
#----------------------------------------------------------------------------- |
|
|
53 | #----------------------------------------------------------------------------- | |
|
54 | 54 | # Frontend class using ipython0 to do the prefiltering. |
|
55 |
#----------------------------------------------------------------------------- |
|
|
55 | #----------------------------------------------------------------------------- | |
|
56 | ||
|
56 | 57 | class PrefilterFrontEnd(LineFrontEndBase): |
|
57 | 58 | """ Class that uses ipython0 to do prefilter the input, do the |
|
58 | 59 | completion and the magics. |
@@ -65,19 +66,13 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
65 | 66 | |
|
66 | 67 | debug = False |
|
67 | 68 | |
|
68 |
def __init__(self, ipython0=None, |
|
|
69 | def __init__(self, ipython0=None, *args, **kwargs): | |
|
69 | 70 | """ Parameters |
|
70 | 71 | ---------- |
|
71 | 72 | |
|
72 | 73 | ipython0: an optional ipython0 instance to use for command |
|
73 | 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 | 76 | LineFrontEndBase.__init__(self, *args, **kwargs) |
|
82 | 77 | self.shell.output_trap = RedirectorOutputTrap( |
|
83 | 78 | out_callback=self.write, |
@@ -90,22 +85,19 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||
|
90 | 85 | # Start the ipython0 instance: |
|
91 | 86 | self.save_output_hooks() |
|
92 | 87 | if ipython0 is None: |
|
93 |
# Instanciate an IPython0 |
|
|
88 | # Instanciate an IPython0 InteractiveShell to be able to use the | |
|
94 | 89 | # prefiltering. |
|
95 | 90 | # Suppress all key input, to avoid waiting |
|
96 | 91 | def my_rawinput(x=None): |
|
97 | 92 | return '\n' |
|
98 | 93 | old_rawinput = __builtin__.raw_input |
|
99 | 94 | __builtin__.raw_input = my_rawinput |
|
100 |
ipython0 = I |
|
|
101 |
|
|
|
102 |
|
|
|
103 | ipython0.initialize() | |
|
95 | ipython0 = InteractiveShell( | |
|
96 | parent=None, user_ns=self.shell.user_ns, | |
|
97 | user_global_ns=self.shell.user_global_ns | |
|
98 | ) | |
|
104 | 99 | __builtin__.raw_input = old_rawinput |
|
105 | # XXX This will need to be updated as we refactor things, but for now, | |
|
106 | # the .shell attribute of the ipythonapp instance conforms to the old | |
|
107 | # api. | |
|
108 | self.ipython0 = ipython0.shell | |
|
100 | self.ipython0 = ipython0 | |
|
109 | 101 | # Set the pager: |
|
110 | 102 | self.ipython0.set_hook('show_in_pager', |
|
111 | 103 | lambda s, string: self.write("\n" + string)) |
@@ -1,14 +1,11 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | ||
|
3 | 2 | """This file contains unittests for the asyncfrontendbase module.""" |
|
4 | ||
|
5 | __docformat__ = "restructuredtext en" | |
|
6 | 3 | |
|
7 | 4 | # Tell nose to skip this module |
|
8 | 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 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 11 | # the file COPYING, distributed as part of this software. |
@@ -21,7 +21,6 b' from nose.tools import assert_equal' | |||
|
21 | 21 | |
|
22 | 22 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd |
|
23 | 23 | from IPython.testing.globalipapp import get_ipython |
|
24 | from IPython.testing.tools import default_argv | |
|
25 | 24 | |
|
26 | 25 | #----------------------------------------------------------------------------- |
|
27 | 26 | # Support utilities |
@@ -35,7 +34,7 b' class TestPrefilterFrontEnd(PrefilterFrontEnd):' | |||
|
35 | 34 | |
|
36 | 35 | def __init__(self): |
|
37 | 36 | self.out = StringIO() |
|
38 |
PrefilterFrontEnd.__init__(self |
|
|
37 | PrefilterFrontEnd.__init__(self) | |
|
39 | 38 | # Some more code for isolation (yeah, crazy) |
|
40 | 39 | self._on_enter() |
|
41 | 40 | self.out.flush() |
@@ -135,9 +135,10 b' else:' | |||
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | |
|
138 |
#----------------------------------------------------------------------------- |
|
|
138 | #----------------------------------------------------------------------------- | |
|
139 | 139 | # The console widget class |
|
140 |
#----------------------------------------------------------------------------- |
|
|
140 | #----------------------------------------------------------------------------- | |
|
141 | ||
|
141 | 142 | class ConsoleWidget(editwindow.EditWindow): |
|
142 | 143 | """ Specialized styled text control view for console-like workflow. |
|
143 | 144 |
@@ -47,7 +47,7 b' class IPythonXController(WxController):' | |||
|
47 | 47 | self._input_state = 'subprocess' |
|
48 | 48 | self.write('\n', refresh=False) |
|
49 | 49 | self.capture_output() |
|
50 |
self.ipython0. |
|
|
50 | self.ipython0.exit() | |
|
51 | 51 | self.release_output() |
|
52 | 52 | if not self.ipython0.exit_now: |
|
53 | 53 | wx.CallAfter(self.new_prompt, |
@@ -23,8 +23,7 b' import os' | |||
|
23 | 23 | import locale |
|
24 | 24 | from thread_ex import ThreadEx |
|
25 | 25 | |
|
26 | import IPython | |
|
27 | from IPython.core import iplib, ipapp | |
|
26 | from IPython.core import iplib | |
|
28 | 27 | from IPython.utils.io import Term |
|
29 | 28 | |
|
30 | 29 | ############################################################################## |
@@ -88,12 +87,10 b' class NonBlockingIPShell(object):' | |||
|
88 | 87 | via raise_exc() |
|
89 | 88 | ''' |
|
90 | 89 | |
|
91 |
def __init__(self |
|
|
90 | def __init__(self, user_ns={}, user_global_ns=None, | |
|
92 | 91 | cin=None, cout=None, cerr=None, |
|
93 | 92 | ask_exit_handler=None): |
|
94 | 93 | ''' |
|
95 | @param argv: Command line options for IPython | |
|
96 | @type argv: list | |
|
97 | 94 | @param user_ns: User namespace. |
|
98 | 95 | @type user_ns: dictionary |
|
99 | 96 | @param user_global_ns: User global namespace. |
@@ -111,9 +108,9 b' class NonBlockingIPShell(object):' | |||
|
111 | 108 | ''' |
|
112 | 109 | #ipython0 initialisation |
|
113 | 110 | self._IP = None |
|
114 |
self.init_ipython0( |
|
|
115 | cin, cout, cerr, | |
|
116 | ask_exit_handler) | |
|
111 | self.init_ipython0(user_ns, user_global_ns, | |
|
112 | cin, cout, cerr, | |
|
113 | ask_exit_handler) | |
|
117 | 114 | |
|
118 | 115 | #vars used by _execute |
|
119 | 116 | self._iter_more = 0 |
@@ -131,7 +128,7 b' class NonBlockingIPShell(object):' | |||
|
131 | 128 | self._help_text = None |
|
132 | 129 | self._add_button = None |
|
133 | 130 | |
|
134 |
def init_ipython0(self |
|
|
131 | def init_ipython0(self, user_ns={}, user_global_ns=None, | |
|
135 | 132 | cin=None, cout=None, cerr=None, |
|
136 | 133 | ask_exit_handler=None): |
|
137 | 134 | ''' Initialize an ipython0 instance ''' |
@@ -151,17 +148,12 b' class NonBlockingIPShell(object):' | |||
|
151 | 148 | |
|
152 | 149 | #Hack to save sys.displayhook, because ipython seems to overwrite it... |
|
153 | 150 | self.sys_displayhook_ori = sys.displayhook |
|
154 | ||
|
155 | ipython0 = ipapp.IPythonApp(argv,user_ns=user_ns, | |
|
156 | user_global_ns=user_global_ns) | |
|
157 | ipython0.initialize() | |
|
158 | self._IP = ipython0.shell | |
|
159 | ||
|
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) | |
|
151 | ipython0 = iplib.InteractiveShell( | |
|
152 | parent=None, config=None, | |
|
153 | user_ns=user_ns, | |
|
154 | user_global_ns=user_global_ns | |
|
155 | ) | |
|
156 | self._IP = ipython0 | |
|
165 | 157 | |
|
166 | 158 | #we save ipython0 displayhook and we restore sys.displayhook |
|
167 | 159 | self.displayhook = sys.displayhook |
@@ -185,12 +177,10 b' class NonBlockingIPShell(object):' | |||
|
185 | 177 | #we replace the help command |
|
186 | 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. | |
|
189 | from IPython.core import ipapi | |
|
190 | ip = ipapi.get() | |
|
180 | #we disable cpaste magic... until we found a way to use it properly. | |
|
191 | 181 | def bypass_magic(self, arg): |
|
192 | 182 | print '%this magic is currently disabled.' |
|
193 | ip.define_magic('cpaste', bypass_magic) | |
|
183 | ipython0.define_magic('cpaste', bypass_magic) | |
|
194 | 184 | |
|
195 | 185 | import __builtin__ |
|
196 | 186 | __builtin__.raw_input = self._raw_input |
@@ -11,6 +11,7 b' __author__ = "Laurent Dufrechou"' | |||
|
11 | 11 | __email__ = "laurent.dufrechou _at_ gmail.com" |
|
12 | 12 | __license__ = "BSD" |
|
13 | 13 | #----------------------------------------- |
|
14 | ||
|
14 | 15 | class IPythonHistoryPanel(wx.Panel): |
|
15 | 16 | |
|
16 | 17 | def __init__(self, parent,flt_empty=True, |
@@ -361,8 +361,11 b' class IPClusterApp(ApplicationWithClusterDir):' | |||
|
361 | 361 | log.msg('Unexpected error in ipcluster:') |
|
362 | 362 | log.msg(r.getTraceback()) |
|
363 | 363 | log.msg("IPython cluster: stopping") |
|
364 | self.stop_engines() | |
|
365 | self.stop_controller() | |
|
364 | # These return deferreds. We are not doing anything with them | |
|
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 | 369 | # Wait a few seconds to let things shut down. |
|
367 | 370 | reactor.callLater(4.0, reactor.stop) |
|
368 | 371 |
@@ -1,15 +1,18 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | A module to change reload() so that it acts recursively. |
|
4 | To enable it type: | |
|
5 | >>> import __builtin__, deepreload | |
|
6 | >>> __builtin__.reload = deepreload.reload | |
|
4 | To enable it type:: | |
|
7 | 5 | |
|
8 | You can then disable it with: | |
|
9 |
|
|
|
6 | import __builtin__, deepreload | |
|
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: | |
|
12 | >>> __builtin__.dreload = deepreload.reload | |
|
13 | Alternatively, you can add a dreload builtin alongside normal reload with:: | |
|
14 | ||
|
15 | __builtin__.dreload = deepreload.reload | |
|
13 | 16 | |
|
14 | 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 | 97 | # correct for that ourselves, to ensure consitency with the 'real' |
|
98 | 98 | # ipython. |
|
99 | 99 | self['__builtins__'] = __builtin__ |
|
100 | ||
|
100 | ||
|
101 | 101 | |
|
102 | 102 | def get_ipython(): |
|
103 | 103 | # This will get replaced by the real thing once we start IPython below |
|
104 | 104 | return start_ipython() |
|
105 | 105 | |
|
106 | ||
|
106 | 107 | def start_ipython(): |
|
107 | 108 | """Start a global IPython shell, which we need for IPython-specific syntax. |
|
108 | 109 | """ |
|
109 | 110 | global get_ipython |
|
110 | 111 | |
|
111 | 112 | # This function should only ever run once! |
|
112 | if hasattr(start_ipython,'already_called'): | |
|
113 | if hasattr(start_ipython, 'already_called'): | |
|
113 | 114 | return |
|
114 | 115 | start_ipython.already_called = True |
|
115 | 116 | |
|
116 | 117 | # Ok, first time we're called, go ahead |
|
117 |
from IPython.core import |
|
|
118 | from IPython.core import iplib | |
|
118 | 119 | |
|
119 | 120 | def xsys(cmd): |
|
120 | 121 | """Execute a command and print its output. |
@@ -132,26 +133,27 b' def start_ipython():' | |||
|
132 | 133 | _main = sys.modules.get('__main__') |
|
133 | 134 | |
|
134 | 135 | # Create custom argv and namespaces for our IPython to be test-friendly |
|
135 |
|
|
|
136 | user_ns, global_ns = iplib.make_user_namespaces(ipnsdict(), {}) | |
|
137 | ||
|
136 | config = tools.default_config() | |
|
137 | ||
|
138 | 138 | # Create and initialize our test-friendly IPython instance. |
|
139 | ip = ipapp.IPythonApp(argv, user_ns=user_ns, user_global_ns=global_ns) | |
|
140 | ip.initialize() | |
|
139 | shell = iplib.InteractiveShell( | |
|
140 | parent=None, config=config, | |
|
141 | user_ns=ipnsdict(), user_global_ns={} | |
|
142 | ) | |
|
141 | 143 | |
|
142 | 144 | # A few more tweaks needed for playing nicely with doctests... |
|
143 | 145 | |
|
144 | 146 | # These traps are normally only active for interactive use, set them |
|
145 | 147 | # permanently since we'll be mocking interactive sessions. |
|
146 |
|
|
|
148 | shell.builtin_trap.set() | |
|
147 | 149 | |
|
148 | 150 | # Set error printing to stdout so nose can doctest exceptions |
|
149 |
|
|
|
151 | shell.InteractiveTB.out_stream = 'stdout' | |
|
150 | 152 | |
|
151 | 153 | # Modify the IPython system call with one that uses getoutput, so that we |
|
152 | 154 | # can capture subcommands and print them to Python's stdout, otherwise the |
|
153 | 155 | # doctest machinery would miss them. |
|
154 |
|
|
|
156 | shell.system = xsys | |
|
155 | 157 | |
|
156 | 158 | # IPython is ready, now clean up some global state... |
|
157 | 159 | |
@@ -164,7 +166,7 b' def start_ipython():' | |||
|
164 | 166 | # So that ipython magics and aliases can be doctested (they work by making |
|
165 | 167 | # a call into a global _ip object). Also make the top-level get_ipython |
|
166 | 168 | # now return this without recursively calling here again. |
|
167 |
_ip = |
|
|
169 | _ip = shell | |
|
168 | 170 | get_ipython = _ip.get_ipython |
|
169 | 171 | __builtin__._ip = _ip |
|
170 | 172 | __builtin__.get_ipython = get_ipython |
@@ -343,9 +343,9 b' def make_runners():' | |||
|
343 | 343 | |
|
344 | 344 | # And add twisted ones if conditions are met |
|
345 | 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 | |
|
347 | # twisted-based, because nose picks up doctests that twisted doesn't. | |
|
348 | nose_pkg_names.append('kernel') | |
|
346 | # We only list IPython.kernel for testing using twisted.trial as | |
|
347 | # nose and twisted.trial have conflicts that make the testing system | |
|
348 | # unstable. | |
|
349 | 349 | trial_pkg_names.append('kernel') |
|
350 | 350 | |
|
351 | 351 | # For debugging this code, only load quick stuff |
@@ -41,6 +41,7 b' try:' | |||
|
41 | 41 | except ImportError: |
|
42 | 42 | has_nose = False |
|
43 | 43 | |
|
44 | from IPython.config.loader import Config | |
|
44 | 45 | from IPython.utils.process import find_cmd, getoutputerror |
|
45 | 46 | from IPython.utils.text import list_strings |
|
46 | 47 | from IPython.utils.io import temp_pyfile |
@@ -165,7 +166,16 b' def default_argv():' | |||
|
165 | 166 | # Other defaults to minimize side effects on stdout |
|
166 | 167 | '--colors=NoColor', '--no-term-title','--no-banner', |
|
167 | 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 | 180 | def ipexec(fname, options=None): |
|
171 | 181 | """Utility to call 'ipython filename'. |
@@ -249,9 +249,7 b' def get_ipython_dir():' | |||
|
249 | 249 | and the adds .ipython to the end of the path. |
|
250 | 250 | """ |
|
251 | 251 | ipdir_def = '.ipython' |
|
252 | print get_home_dir | |
|
253 | 252 | home_dir = get_home_dir() |
|
254 | print home_dir | |
|
255 | 253 | #import pdb; pdb.set_trace() # dbg |
|
256 | 254 | ipdir = os.environ.get( |
|
257 | 255 | 'IPYTHON_DIR', os.environ.get( |
@@ -244,7 +244,7 b' and an example of ``# all-random``::' | |||
|
244 | 244 | |
|
245 | 245 | When writing docstrings, you can use the ``@skip_doctest`` decorator to |
|
246 | 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 | 248 | executes the example but ignores output, while the latter doesn't execute any |
|
249 | 249 | code. ``@skip_doctest`` should be used for docstrings whose examples are |
|
250 | 250 | purely informational. |
@@ -59,12 +59,9 b' Authors' | |||
|
59 | 59 | |
|
60 | 60 | # Stdlib |
|
61 | 61 | import cStringIO |
|
62 | import imp | |
|
63 | 62 | import os |
|
64 | 63 | import re |
|
65 | import shutil | |
|
66 | 64 | import sys |
|
67 | import warnings | |
|
68 | 65 | |
|
69 | 66 | # To keep compatibility with various python versions |
|
70 | 67 | try: |
@@ -80,8 +77,8 b' from docutils.parsers.rst import directives' | |||
|
80 | 77 | matplotlib.use('Agg') |
|
81 | 78 | |
|
82 | 79 | # Our own |
|
83 |
from IPython import Config, I |
|
|
84 |
from IPython.utils.io import Term |
|
|
80 | from IPython import Config, InteractiveShell | |
|
81 | from IPython.utils.io import Term | |
|
85 | 82 | |
|
86 | 83 | #----------------------------------------------------------------------------- |
|
87 | 84 | # Globals |
@@ -222,15 +219,11 b' class EmbeddedSphinxShell(object):' | |||
|
222 | 219 | config.InteractiveShell.autoindent = False |
|
223 | 220 | config.InteractiveShell.colors = 'NoColor' |
|
224 | 221 | |
|
225 | # Merge global config which can be used to override. | |
|
226 | config._merge(CONFIG) | |
|
227 | ||
|
228 | 222 | # Create and initialize ipython, but don't start its mainloop |
|
229 |
IP = I |
|
|
230 | IP.initialize() | |
|
223 | IP = InteractiveShell(parent=None, config=config) | |
|
231 | 224 | |
|
232 | 225 | # Store a few parts of IPython we'll need. |
|
233 |
self.IP = IP |
|
|
226 | self.IP = IP | |
|
234 | 227 | self.user_ns = self.IP.user_ns |
|
235 | 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