##// END OF EJS Templates
More work to address review comments....
Brian Granger -
Show More
@@ -833,7 +833,7 b' class InteractiveShell(Component, Magic):'
833 # loaded at startup, so we can list later only variables defined in
833 # loaded at startup, so we can list later only variables defined in
834 # actual interactive use. Since it is always a subset of user_ns, it
834 # actual interactive use. Since it is always a subset of user_ns, it
835 # doesn't need to be separately tracked in the ns_table.
835 # doesn't need to be separately tracked in the ns_table.
836 self.user_config_ns = {}
836 self.user_ns_hidden = {}
837
837
838 # A namespace to keep track of internal data structures to prevent
838 # A namespace to keep track of internal data structures to prevent
839 # them from cluttering user-visible stuff. Will be updated later
839 # them from cluttering user-visible stuff. Will be updated later
@@ -879,7 +879,7 b' class InteractiveShell(Component, Magic):'
879 # Similarly, track all namespaces where references can be held and that
879 # Similarly, track all namespaces where references can be held and that
880 # we can safely clear (so it can NOT include builtin). This one can be
880 # we can safely clear (so it can NOT include builtin). This one can be
881 # a simple list.
881 # a simple list.
882 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_ns_hidden,
883 self.internal_ns, self._main_ns_cache ]
883 self.internal_ns, self._main_ns_cache ]
884
884
885 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
885 def make_user_namespaces(self, user_ns=None, user_global_ns=None):
@@ -978,7 +978,7 b' class InteractiveShell(Component, Magic):'
978 therm.
978 therm.
979 """
979 """
980 # This function works in two parts: first we put a few things in
980 # This function works in two parts: first we put a few things in
981 # user_ns, and we sync that contents into user_config_ns so that these
981 # user_ns, and we sync that contents into user_ns_hidden so that these
982 # initial variables aren't shown by %who. After the sync, we add the
982 # initial variables aren't shown by %who. After the sync, we add the
983 # rest of what we *do* want the user to see with %who even on a new
983 # rest of what we *do* want the user to see with %who even on a new
984 # session (probably nothing, so theye really only see their own stuff)
984 # session (probably nothing, so theye really only see their own stuff)
@@ -1018,9 +1018,9 b' class InteractiveShell(Component, Magic):'
1018 # Store myself as the public api!!!
1018 # Store myself as the public api!!!
1019 ns['get_ipython'] = self.get_ipython
1019 ns['get_ipython'] = self.get_ipython
1020
1020
1021 # Sync what we've added so far to user_config_ns so these aren't seen
1021 # Sync what we've added so far to user_ns_hidden so these aren't seen
1022 # by %who
1022 # by %who
1023 self.user_config_ns.update(ns)
1023 self.user_ns_hidden.update(ns)
1024
1024
1025 # Anything put into ns now would show up in %who. Think twice before
1025 # Anything put into ns now would show up in %who. Think twice before
1026 # putting anything here, as we really want %who to show the user their
1026 # putting anything here, as we really want %who to show the user their
@@ -1093,7 +1093,7 b' class InteractiveShell(Component, Magic):'
1093 self.user_ns.update(vdict)
1093 self.user_ns.update(vdict)
1094
1094
1095 # And configure interactive visibility
1095 # And configure interactive visibility
1096 config_ns = self.user_config_ns
1096 config_ns = self.user_ns_hidden
1097 if interactive:
1097 if interactive:
1098 for name, val in vdict.iteritems():
1098 for name, val in vdict.iteritems():
1099 config_ns.pop(name, None)
1099 config_ns.pop(name, None)
@@ -2360,6 +2360,9 b' class InteractiveShell(Component, Magic):'
2360 to make it easy to write extensions, you can also put your extensions
2360 to make it easy to write extensions, you can also put your extensions
2361 in ``os.path.join(self.ipython_dir, 'extensions')``. This directory
2361 in ``os.path.join(self.ipython_dir, 'extensions')``. This directory
2362 is added to ``sys.path`` automatically.
2362 is added to ``sys.path`` automatically.
2363
2364 If :func:`load_ipython_extension` returns anything, this function
2365 will return that object.
2363 """
2366 """
2364 from IPython.utils.syspathcontext import prepended_to_syspath
2367 from IPython.utils.syspathcontext import prepended_to_syspath
2365
2368
@@ -2504,11 +2507,11 b' class InteractiveShell(Component, Magic):'
2504 # We want to prevent the loading of pylab to pollute the user's
2507 # We want to prevent the loading of pylab to pollute the user's
2505 # namespace as shown by the %who* magics, so we execute the activation
2508 # namespace as shown by the %who* magics, so we execute the activation
2506 # code in an empty namespace, and we update *both* user_ns and
2509 # code in an empty namespace, and we update *both* user_ns and
2507 # user_config_ns with this information.
2510 # user_ns_hidden with this information.
2508 ns = {}
2511 ns = {}
2509 gui = pylab_activate(ns, gui)
2512 gui = pylab_activate(ns, gui)
2510 self.user_ns.update(ns)
2513 self.user_ns.update(ns)
2511 self.user_config_ns.update(ns)
2514 self.user_ns_hidden.update(ns)
2512 # Now we must activate the gui pylab wants to use, and fix %run to take
2515 # Now we must activate the gui pylab wants to use, and fix %run to take
2513 # plot updates into account
2516 # plot updates into account
2514 enable_gui(gui)
2517 enable_gui(gui)
@@ -886,10 +886,10 b' Currently the magic system has the following functions:\\n"""'
886
886
887 user_ns = self.shell.user_ns
887 user_ns = self.shell.user_ns
888 internal_ns = self.shell.internal_ns
888 internal_ns = self.shell.internal_ns
889 user_config_ns = self.shell.user_config_ns
889 user_ns_hidden = self.shell.user_ns_hidden
890 out = [ i for i in user_ns
890 out = [ i for i in user_ns
891 if not i.startswith('_') \
891 if not i.startswith('_') \
892 and not (i in internal_ns or i in user_config_ns) ]
892 and not (i in internal_ns or i in user_ns_hidden) ]
893
893
894 typelist = parameter_s.split()
894 typelist = parameter_s.split()
895 if typelist:
895 if typelist:
@@ -30,9 +30,9 b' ip = get_ipython()'
30 @dec.parametric
30 @dec.parametric
31 def test_reset():
31 def test_reset():
32 """reset must clear most namespaces."""
32 """reset must clear most namespaces."""
33 # The number of variables in the private user_config_ns is not zero, but it
33 # The number of variables in the private user_ns_hidden is not zero, but it
34 # should be constant regardless of what we do
34 # should be constant regardless of what we do
35 nvars_config_ns = len(ip.user_config_ns)
35 nvars_config_ns = len(ip.user_ns_hidden)
36
36
37 # Check that reset runs without error
37 # Check that reset runs without error
38 ip.reset()
38 ip.reset()
@@ -51,7 +51,7 b' def test_reset():'
51 for ns in ip.ns_refs_table:
51 for ns in ip.ns_refs_table:
52 if ns is ip.user_ns:
52 if ns is ip.user_ns:
53 nvars_expected = nvars_user_ns
53 nvars_expected = nvars_user_ns
54 elif ns is ip.user_config_ns:
54 elif ns is ip.user_ns_hidden:
55 nvars_expected = nvars_config_ns
55 nvars_expected = nvars_config_ns
56 else:
56 else:
57 nvars_expected = 0
57 nvars_expected = 0
@@ -18,6 +18,8 b' __test__ = {}'
18 # Imports
18 # Imports
19 #-------------------------------------------------------------------------------
19 #-------------------------------------------------------------------------------
20
20
21 from twisted.python import failure
22
21 from IPython.kernel.core import error
23 from IPython.kernel.core import error
22
24
23 #-------------------------------------------------------------------------------
25 #-------------------------------------------------------------------------------
@@ -27,6 +29,7 b' from IPython.kernel.core import error'
27 class KernelError(error.IPythonError):
29 class KernelError(error.IPythonError):
28 pass
30 pass
29
31
32
30 class NotDefined(KernelError):
33 class NotDefined(KernelError):
31 def __init__(self, name):
34 def __init__(self, name):
32 self.name = name
35 self.name = name
@@ -37,78 +40,102 b' class NotDefined(KernelError):'
37
40
38 __str__ = __repr__
41 __str__ = __repr__
39
42
43
40 class QueueCleared(KernelError):
44 class QueueCleared(KernelError):
41 pass
45 pass
42
46
47
43 class IdInUse(KernelError):
48 class IdInUse(KernelError):
44 pass
49 pass
45
50
51
46 class ProtocolError(KernelError):
52 class ProtocolError(KernelError):
47 pass
53 pass
48
54
55
49 class ConnectionError(KernelError):
56 class ConnectionError(KernelError):
50 pass
57 pass
51
58
59
52 class InvalidEngineID(KernelError):
60 class InvalidEngineID(KernelError):
53 pass
61 pass
54
62
63
55 class NoEnginesRegistered(KernelError):
64 class NoEnginesRegistered(KernelError):
56 pass
65 pass
57
66
67
58 class InvalidClientID(KernelError):
68 class InvalidClientID(KernelError):
59 pass
69 pass
60
70
71
61 class InvalidDeferredID(KernelError):
72 class InvalidDeferredID(KernelError):
62 pass
73 pass
63
74
75
64 class SerializationError(KernelError):
76 class SerializationError(KernelError):
65 pass
77 pass
66
78
79
67 class MessageSizeError(KernelError):
80 class MessageSizeError(KernelError):
68 pass
81 pass
69
82
83
70 class PBMessageSizeError(MessageSizeError):
84 class PBMessageSizeError(MessageSizeError):
71 pass
85 pass
72
86
87
73 class ResultNotCompleted(KernelError):
88 class ResultNotCompleted(KernelError):
74 pass
89 pass
75
90
91
76 class ResultAlreadyRetrieved(KernelError):
92 class ResultAlreadyRetrieved(KernelError):
77 pass
93 pass
78
94
79 class ClientError(KernelError):
95 class ClientError(KernelError):
80 pass
96 pass
81
97
98
82 class TaskAborted(KernelError):
99 class TaskAborted(KernelError):
83 pass
100 pass
84
101
102
85 class TaskTimeout(KernelError):
103 class TaskTimeout(KernelError):
86 pass
104 pass
87
105
106
88 class NotAPendingResult(KernelError):
107 class NotAPendingResult(KernelError):
89 pass
108 pass
90
109
110
91 class UnpickleableException(KernelError):
111 class UnpickleableException(KernelError):
92 pass
112 pass
93
113
114
94 class AbortedPendingDeferredError(KernelError):
115 class AbortedPendingDeferredError(KernelError):
95 pass
116 pass
96
117
118
97 class InvalidProperty(KernelError):
119 class InvalidProperty(KernelError):
98 pass
120 pass
99
121
122
100 class MissingBlockArgument(KernelError):
123 class MissingBlockArgument(KernelError):
101 pass
124 pass
102
125
126
103 class StopLocalExecution(KernelError):
127 class StopLocalExecution(KernelError):
104 pass
128 pass
105
129
130
106 class SecurityError(KernelError):
131 class SecurityError(KernelError):
107 pass
132 pass
108
133
134
109 class FileTimeoutError(KernelError):
135 class FileTimeoutError(KernelError):
110 pass
136 pass
111
137
138
112 class TaskRejectError(KernelError):
139 class TaskRejectError(KernelError):
113 """Exception to raise when a task should be rejected by an engine.
140 """Exception to raise when a task should be rejected by an engine.
114
141
@@ -123,6 +150,7 b' class TaskRejectError(KernelError):'
123 properties don't have to be managed or tested by the controller.
150 properties don't have to be managed or tested by the controller.
124 """
151 """
125
152
153
126 class CompositeError(KernelError):
154 class CompositeError(KernelError):
127 def __init__(self, message, elist):
155 def __init__(self, message, elist):
128 Exception.__init__(self, *(message, elist))
156 Exception.__init__(self, *(message, elist))
@@ -177,9 +205,8 b' class CompositeError(KernelError):'
177 else:
205 else:
178 raise et, ev, etb
206 raise et, ev, etb
179
207
180 def collect_exceptions(rlist, method):
181 from twisted.python import failure
182
208
209 def collect_exceptions(rlist, method):
183 elist = []
210 elist = []
184 for r in rlist:
211 for r in rlist:
185 if isinstance(r, failure.Failure):
212 if isinstance(r, failure.Failure):
@@ -188,11 +188,6 b' def get_home_dir():'
188 # is needed when running IPython on cluster where all paths have to
188 # is needed when running IPython on cluster where all paths have to
189 # be UNC.
189 # be UNC.
190 try:
190 try:
191 # A user with a lot of unix tools in win32 may have defined $HOME,
192 # honor it if it exists, but otherwise let the more typical
193 # %HOMESHARE% variable be used.
194 homedir = env.get('HOME')
195 if homedir is None:
196 homedir = env['HOMESHARE']
191 homedir = env['HOMESHARE']
197 except KeyError:
192 except KeyError:
198 pass
193 pass
@@ -233,6 +228,16 b' def get_home_dir():'
233 if isdir(homedir):
228 if isdir(homedir):
234 return homedir.decode(sys.getfilesystemencoding())
229 return homedir.decode(sys.getfilesystemencoding())
235
230
231 # A user with a lot of unix tools in win32 may have defined $HOME.
232 # Try this as a last ditch option.
233 try:
234 homedir = env['HOME']
235 except KeyError:
236 pass
237 else:
238 if isdir(homedir):
239 return homedir.decode(sys.getfilesystemencoding())
240
236 # If all else fails, raise HomeDirError
241 # If all else fails, raise HomeDirError
237 raise HomeDirError('No valid home directory could be found')
242 raise HomeDirError('No valid home directory could be found')
238 elif os.name == 'dos':
243 elif os.name == 'dos':
General Comments 0
You need to be logged in to leave comments. Login now