##// END OF EJS Templates
Remove 2.3 compatibility, minor cleanups.
Fernando Perez -
Show More
@@ -1,4 +1,4 b''
1 ''' IPython customization API
1 """IPython customization API
2 2
3 3 Your one-stop module for configuring & extending ipython
4 4
@@ -58,20 +58,20 b' o = ip.options'
58 58 o.autocall = 2 # FULL autocall mode
59 59
60 60 print "done!"
61 '''
61 """
62
63 #-----------------------------------------------------------------------------
64 # Modules and globals
62 65
63 66 # stdlib imports
64 67 import __builtin__
65 68 import sys
66 69
67 try: # Python 2.3 compatibility
68 set
69 except NameError:
70 import sets
71 set = sets.Set
70 # contains the most recently instantiated IPApi
71 _RECENT_IP = None
72 72
73 # our own
74 #from IPython.genutils import warn,error
73 #-----------------------------------------------------------------------------
74 # Code begins
75 75
76 76 class TryNext(Exception):
77 77 """Try next hook exception.
@@ -109,7 +109,6 b' class IPyAutocall:'
109 109 self._ip = ip
110 110
111 111
112 # contains the most recently instantiated IPApi
113 112
114 113 class IPythonNotRunning:
115 114 """Dummy do-nothing class.
@@ -144,8 +143,6 b' class IPythonNotRunning:'
144 143 """Dummy function, which doesn't do anything and emits no warnings."""
145 144 pass
146 145
147 _recent = None
148
149 146
150 147 def get(allow_dummy=False,dummy_warn=True):
151 148 """Get an IPApi object.
@@ -159,10 +156,10 b' def get(allow_dummy=False,dummy_warn=True):'
159 156 can be imported as normal modules. You can then direct all the
160 157 configuration operations against the returned object.
161 158 """
162 global _recent
163 if allow_dummy and not _recent:
164 _recent = IPythonNotRunning(dummy_warn)
165 return _recent
159 global _RECENT_IP
160 if allow_dummy and not _RECENT_IP:
161 _RECENT_IP = IPythonNotRunning(dummy_warn)
162 return _RECENT_IP
166 163
167 164 class IPApi:
168 165 """ The actual API class for configuring IPython
@@ -173,6 +170,8 b' class IPApi:'
173 170
174 171 def __init__(self,ip):
175 172
173 global _RECENT_IP
174
176 175 # All attributes exposed here are considered to be the public API of
177 176 # IPython. As needs dictate, some of these may be wrapped as
178 177 # properties.
@@ -201,8 +200,7 b' class IPApi:'
201 200
202 201 self.dbg = DebugTools(self)
203 202
204 global _recent
205 _recent = self
203 _RECENT_IP = self
206 204
207 205 # Use a property for some things which are added to the instance very
208 206 # late. I don't have time right now to disentangle the initialization
@@ -218,8 +216,8 b' class IPApi:'
218 216 """All configurable variables."""
219 217
220 218 # catch typos by disabling new attribute creation. If new attr creation
221 # is in fact wanted (e.g. when exposing new options), do allow_new_attr(True)
222 # for the received rc struct.
219 # is in fact wanted (e.g. when exposing new options), do
220 # allow_new_attr(True) for the received rc struct.
223 221
224 222 self.IP.rc.allow_new_attr(False)
225 223 return self.IP.rc
@@ -267,10 +265,10 b' class IPApi:'
267 265 def cleanup_ipy_script(script):
268 266 """ Make a script safe for _ip.runlines()
269 267
270 - Removes empty lines
271 - Suffixes all indented blocks that end with unindented lines with empty lines
272
268 - Removes empty lines Suffixes all indented blocks that end with
269 - unindented lines with empty lines
273 270 """
271
274 272 res = []
275 273 lines = script.splitlines()
276 274
@@ -290,7 +288,8 b' class IPApi:'
290 288 s.startswith('finally')):
291 289 return True
292 290
293 if level > 0 and newlevel == 0 and not is_secondary_block_start(stripped):
291 if level > 0 and newlevel == 0 and \
292 not is_secondary_block_start(stripped):
294 293 # add empty line
295 294 res.append('')
296 295
@@ -305,6 +304,7 b' class IPApi:'
305 304 clean=cleanup_ipy_script(script)
306 305 # print "_ip.runlines() script:\n",clean #dbg
307 306 self.IP.runlines(clean)
307
308 308 def to_user_ns(self,vars, interactive = True):
309 309 """Inject a group of variables into the IPython user namespace.
310 310
@@ -392,7 +392,6 b' class IPApi:'
392 392 for name,val in vdict.iteritems():
393 393 config_ns[name] = val
394 394
395
396 395 def expand_alias(self,line):
397 396 """ Expand an alias in the command line
398 397
@@ -425,11 +424,9 b' class IPApi:'
425 424
426 425 self.dbg.check_hotname(name)
427 426
428
429 427 if name in self.IP.alias_table:
430 self.dbg.debug_stack("Alias redefinition: '%s' => '%s' (old '%s')" %
431 (name, cmd, self.IP.alias_table[name]))
432
428 self.dbg.debug_stack("Alias redefinition: '%s' => '%s' (old '%s')"
429 % (name, cmd, self.IP.alias_table[name]))
433 430
434 431 if callable(cmd):
435 432 self.IP.alias_table[name] = cmd
@@ -440,8 +437,8 b' class IPApi:'
440 437 if isinstance(cmd,basestring):
441 438 nargs = cmd.count('%s')
442 439 if nargs>0 and cmd.find('%l')>=0:
443 raise Exception('The %s and %l specifiers are mutually exclusive '
444 'in alias definitions.')
440 raise Exception('The %s and %l specifiers are mutually '
441 'exclusive in alias definitions.')
445 442
446 443 self.IP.alias_table[name] = (nargs,cmd)
447 444 return
@@ -494,8 +491,8 b' class IPApi:'
494 491
495 492 - run init_ipython(ip)
496 493 - run ipython_firstrun(ip)
497
498 494 """
495
499 496 if mod in self.extensions:
500 497 # just to make sure we don't init it twice
501 498 # note that if you 'load' a module that has already been
@@ -545,6 +542,7 b' class DebugTools:'
545 542 if name in self.hotnames:
546 543 self.debug_stack( "HotName '%s' caught" % name)
547 544
545
548 546 def launch_new_instance(user_ns = None,shellclass = None):
549 547 """ Make and start a new ipython instance.
550 548
General Comments 0
You need to be logged in to leave comments. Login now