##// END OF EJS Templates
Merge my trunk-dev, with following mods:...
Ville M. Vainio -
r1737:2a72a835 merge
parent child Browse files
Show More
@@ -0,0 +1,21 b''
1 """ Tests for various magic functions
2
3 Needs to be run by nose (to make ipython session available)
4
5 """
6 def test_rehashx():
7 # clear up everything
8 _ip.IP.alias_table.clear()
9 del _ip.db['syscmdlist']
10
11 _ip.magic('rehashx')
12 # Practically ALL ipython development systems will have more than 10 aliases
13
14 assert len(_ip.IP.alias_table) > 10
15 for key, val in _ip.IP.alias_table.items():
16 # we must strip dots from alias names
17 assert '.' not in key
18
19 # rehashx must fill up syscmdlist
20 scoms = _ip.db['syscmdlist']
21 assert len(scoms) > 10
@@ -335,6 +335,12 b' def cd_completer(self, event):'
335 if not found:
335 if not found:
336 if os.path.isdir(relpath):
336 if os.path.isdir(relpath):
337 return [relpath]
337 return [relpath]
338 # if no completions so far, try bookmarks
339 bks = self.db.get('bookmarks',{}).keys()
340 bkmatches = [s for s in bks if s.startswith(event.symbol)]
341 if bkmatches:
342 return bkmatches
343
338 raise IPython.ipapi.TryNext
344 raise IPython.ipapi.TryNext
339
345
340
346
@@ -50,9 +50,15 b' def main():'
50 ip.ex('import os')
50 ip.ex('import os')
51 ip.ex("def up(): os.chdir('..')")
51 ip.ex("def up(): os.chdir('..')")
52 ip.user_ns['LA'] = LastArgFinder()
52 ip.user_ns['LA'] = LastArgFinder()
53 # Nice prompt
54
53
55 o.prompt_in1= r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#> '
54 # You can assign to _prompt_title variable
55 # to provide some extra information for prompt
56 # (e.g. the current mode, host/username...)
57
58 ip.user_ns['_prompt_title'] = ''
59
60 # Nice prompt
61 o.prompt_in1= r'\C_Green${_prompt_title}\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Green|\#> '
56 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green> '
62 o.prompt_in2= r'\C_Green|\C_LightGreen\D\C_Green> '
57 o.prompt_out= '<\#> '
63 o.prompt_out= '<\#> '
58
64
@@ -98,9 +104,15 b' def main():'
98 for cmd in syscmds:
104 for cmd in syscmds:
99 # print "sys",cmd #dbg
105 # print "sys",cmd #dbg
100 noext, ext = os.path.splitext(cmd)
106 noext, ext = os.path.splitext(cmd)
101 key = mapper(noext)
107 if ext.lower() == '.exe':
108 cmd = noext
109
110 key = mapper(cmd)
102 if key not in ip.IP.alias_table:
111 if key not in ip.IP.alias_table:
103 ip.defalias(key, cmd)
112 # Dots will be removed from alias names, since ipython
113 # assumes names with dots to be python code
114
115 ip.defalias(key.replace('.',''), cmd)
104
116
105 # mglob combines 'find', recursion, exclusion... '%mglob?' to learn more
117 # mglob combines 'find', recursion, exclusion... '%mglob?' to learn more
106 ip.load("IPython.external.mglob")
118 ip.load("IPython.external.mglob")
@@ -2329,6 +2329,12 b' Currently the magic system has the following functions:\\n"""'
2329 print 'Editing...',
2329 print 'Editing...',
2330 sys.stdout.flush()
2330 sys.stdout.flush()
2331 self.shell.hooks.editor(filename,lineno)
2331 self.shell.hooks.editor(filename,lineno)
2332
2333 # XXX TODO: should this be generalized for all string vars?
2334 # For now, this is special-cased to blocks created by cpaste
2335 if args.strip() == 'pasted_block':
2336 self.shell.user_ns['pasted_block'] = file_read(filename)
2337
2332 if opts.has_key('x'): # -x prevents actual execution
2338 if opts.has_key('x'): # -x prevents actual execution
2333 print
2339 print
2334 else:
2340 else:
@@ -2338,6 +2344,8 b' Currently the magic system has the following functions:\\n"""'
2338 else:
2344 else:
2339 self.shell.safe_execfile(filename,self.shell.user_ns,
2345 self.shell.safe_execfile(filename,self.shell.user_ns,
2340 self.shell.user_ns)
2346 self.shell.user_ns)
2347
2348
2341 if use_temp:
2349 if use_temp:
2342 try:
2350 try:
2343 return open(filename).read()
2351 return open(filename).read()
@@ -2647,8 +2655,10 b' Defaulting color scheme to \'NoColor\'"""'
2647 if isexec(ff) and ff not in self.shell.no_alias:
2655 if isexec(ff) and ff not in self.shell.no_alias:
2648 # each entry in the alias table must be (N,name),
2656 # each entry in the alias table must be (N,name),
2649 # where N is the number of positional arguments of the
2657 # where N is the number of positional arguments of the
2650 # alias.
2658 # alias.
2651 alias_table[ff] = (0,ff)
2659 # Dots will be removed from alias names, since ipython
2660 # assumes names with dots to be python code
2661 alias_table[ff.replace('.','')] = (0,ff)
2652 syscmdlist.append(ff)
2662 syscmdlist.append(ff)
2653 else:
2663 else:
2654 for pdir in path:
2664 for pdir in path:
@@ -2658,7 +2668,7 b' Defaulting color scheme to \'NoColor\'"""'
2658 if isexec(ff) and base.lower() not in self.shell.no_alias:
2668 if isexec(ff) and base.lower() not in self.shell.no_alias:
2659 if ext.lower() == '.exe':
2669 if ext.lower() == '.exe':
2660 ff = base
2670 ff = base
2661 alias_table[base.lower()] = (0,ff)
2671 alias_table[base.lower().replace('.','')] = (0,ff)
2662 syscmdlist.append(ff)
2672 syscmdlist.append(ff)
2663 # Make sure the alias table doesn't contain keywords or builtins
2673 # Make sure the alias table doesn't contain keywords or builtins
2664 self.shell.alias_table_validate()
2674 self.shell.alias_table_validate()
@@ -3210,14 +3220,24 b' Defaulting color scheme to \'NoColor\'"""'
3210 This assigns the pasted block to variable 'foo' as string, without
3220 This assigns the pasted block to variable 'foo' as string, without
3211 dedenting or executing it (preceding >>> and + is still stripped)
3221 dedenting or executing it (preceding >>> and + is still stripped)
3212
3222
3223 '%cpaste -r' re-executes the block previously entered by cpaste.
3224
3213 Do not be alarmed by garbled output on Windows (it's a readline bug).
3225 Do not be alarmed by garbled output on Windows (it's a readline bug).
3214 Just press enter and type -- (and press enter again) and the block
3226 Just press enter and type -- (and press enter again) and the block
3215 will be what was just pasted.
3227 will be what was just pasted.
3216
3228
3217 IPython statements (magics, shell escapes) are not supported (yet).
3229 IPython statements (magics, shell escapes) are not supported (yet).
3218 """
3230 """
3219 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3231 opts,args = self.parse_options(parameter_s,'rs:',mode='string')
3220 par = args.strip()
3232 par = args.strip()
3233 if opts.has_key('r'):
3234 b = self.user_ns.get('pasted_block', None)
3235 if b is None:
3236 raise UsageError('No previous pasted block available')
3237 print "Re-executing '%s...' (%d chars)"% (b.split('\n',1)[0], len(b))
3238 exec b in self.user_ns
3239 return
3240
3221 sentinel = opts.get('s','--')
3241 sentinel = opts.get('s','--')
3222
3242
3223 # Regular expressions that declare text we strip from the input:
3243 # Regular expressions that declare text we strip from the input:
@@ -3245,8 +3265,8 b' Defaulting color scheme to \'NoColor\'"""'
3245 #print "block:\n",block
3265 #print "block:\n",block
3246 if not par:
3266 if not par:
3247 b = textwrap.dedent(block)
3267 b = textwrap.dedent(block)
3248 exec b in self.user_ns
3249 self.user_ns['pasted_block'] = b
3268 self.user_ns['pasted_block'] = b
3269 exec b in self.user_ns
3250 else:
3270 else:
3251 self.user_ns[par] = SList(block.splitlines())
3271 self.user_ns[par] = SList(block.splitlines())
3252 print "Block assigned to '%s'" % par
3272 print "Block assigned to '%s'" % par
@@ -8,6 +8,7 b' import os'
8
8
9 # IPython imports
9 # IPython imports
10 from IPython.genutils import Term, ask_yes_no
10 from IPython.genutils import Term, ask_yes_no
11 import IPython.ipapi
11
12
12 def magic_history(self, parameter_s = ''):
13 def magic_history(self, parameter_s = ''):
13 """Print input history (_i<n> variables), with most recent last.
14 """Print input history (_i<n> variables), with most recent last.
@@ -222,6 +223,7 b' class ShadowHist:'
222 # cmd => idx mapping
223 # cmd => idx mapping
223 self.curidx = 0
224 self.curidx = 0
224 self.db = db
225 self.db = db
226 self.disabled = False
225
227
226 def inc_idx(self):
228 def inc_idx(self):
227 idx = self.db.get('shadowhist_idx', 1)
229 idx = self.db.get('shadowhist_idx', 1)
@@ -229,12 +231,19 b' class ShadowHist:'
229 return idx
231 return idx
230
232
231 def add(self, ent):
233 def add(self, ent):
232 old = self.db.hget('shadowhist', ent, _sentinel)
234 if self.disabled:
233 if old is not _sentinel:
234 return
235 return
235 newidx = self.inc_idx()
236 try:
236 #print "new",newidx # dbg
237 old = self.db.hget('shadowhist', ent, _sentinel)
237 self.db.hset('shadowhist',ent, newidx)
238 if old is not _sentinel:
239 return
240 newidx = self.inc_idx()
241 #print "new",newidx # dbg
242 self.db.hset('shadowhist',ent, newidx)
243 except:
244 IPython.ipapi.get().IP.showtraceback()
245 print "WARNING: disabling shadow history"
246 self.disabled = True
238
247
239 def all(self):
248 def all(self):
240 d = self.db.hdict('shadowhist')
249 d = self.db.hdict('shadowhist')
@@ -21,6 +21,32 b" What's new"
21 6 Older releases
21 6 Older releases
22 ..
22 ..
23
23
24 Release DEV
25 ===========
26
27 * cd completer: show bookmarks if no other completions are available.
28
29 * Remove ipy_leo.py. "easy_install ipython-extension" to get it.
30 (done to decouple it from ipython release cycle)
31
32 * sh profile: easy way to give 'title' to prompt: assign to variable
33 '_prompt_title'. It looks like this::
34
35 [~]|1> _prompt_title = 'sudo!'
36 sudo![~]|2>
37
38 * %rehashx: Aliases no longer contain dots. python3.0 binary
39 will create alias python30. Fixes:
40 #259716 "commands with dots in them don't work"
41
42 * %cpaste: %cpaste -r repeats the last pasted block.
43 The block is assigned to pasted_block even if code
44 raises exception.
45
46 * %edit: If you do '%edit pasted_block', pasted_block
47 variable gets updated with new data (so repeated
48 editing makes sense)
49
24
50
25 Release 0.9.1
51 Release 0.9.1
26 =============
52 =============
@@ -12,4 +12,4 b' for f in fs:'
12
12
13 if errs:
13 if errs:
14 print "%3s" % errs, f
14 print "%3s" % errs, f
15 No newline at end of file
15
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (660 lines changed) Show them Hide them
General Comments 0
You need to be logged in to leave comments. Login now