##// END OF EJS Templates
- Various small fixes and cleanups....
fperez -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
2 """Magic functions for InteractiveShell.
3
3
4 $Id: Magic.py 2200 2007-04-03 05:24:30Z fperez $"""
4 $Id: Magic.py 2221 2007-04-06 02:58:37Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -932,7 +932,10 b' Currently the magic system has the following functions:\\n"""'
932
932
933 varlist = self.magic_who_ls(parameter_s)
933 varlist = self.magic_who_ls(parameter_s)
934 if not varlist:
934 if not varlist:
935 print 'Interactive namespace is empty.'
935 if parameter_s:
936 print 'No variables match your requested type.'
937 else:
938 print 'Interactive namespace is empty.'
936 return
939 return
937
940
938 # if we have variables, move on...
941 # if we have variables, move on...
@@ -962,7 +965,10 b' Currently the magic system has the following functions:\\n"""'
962
965
963 varnames = self.magic_who_ls(parameter_s)
966 varnames = self.magic_who_ls(parameter_s)
964 if not varnames:
967 if not varnames:
965 print 'Interactive namespace is empty.'
968 if parameter_s:
969 print 'No variables match your requested type.'
970 else:
971 print 'Interactive namespace is empty.'
966 return
972 return
967
973
968 # if we have variables, move on...
974 # if we have variables, move on...
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Release data for the IPython project.
2 """Release data for the IPython project.
3
3
4 $Id: Release.py 2217 2007-04-05 06:06:26Z fperez $"""
4 $Id: Release.py 2221 2007-04-06 02:58:37Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -25,7 +25,7 b" name = 'ipython'"
25 revision = '2191'
25 revision = '2191'
26
26
27 #version = '0.7.4.svn.r' + revision.rstrip('M')
27 #version = '0.7.4.svn.r' + revision.rstrip('M')
28 version = '0.7.4.rc1'
28 version = '0.8.0'
29
29
30 description = "An enhanced interactive Python shell."
30 description = "An enhanced interactive Python shell."
31
31
@@ -4,7 +4,7 b''
4 All the matplotlib support code was co-developed with John Hunter,
4 All the matplotlib support code was co-developed with John Hunter,
5 matplotlib's author.
5 matplotlib's author.
6
6
7 $Id: Shell.py 2216 2007-04-05 06:00:13Z fperez $"""
7 $Id: Shell.py 2221 2007-04-06 02:58:37Z fperez $"""
8
8
9 #*****************************************************************************
9 #*****************************************************************************
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
10 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -25,6 +25,7 b' import Queue'
25 import inspect
25 import inspect
26 import os
26 import os
27 import sys
27 import sys
28 import thread
28 import threading
29 import threading
29 import time
30 import time
30
31
@@ -36,7 +37,6 b' try:'
36 except ImportError:
37 except ImportError:
37 HAS_CTYPES = False
38 HAS_CTYPES = False
38
39
39
40 # IPython imports
40 # IPython imports
41 import IPython
41 import IPython
42 from IPython import ultraTB
42 from IPython import ultraTB
@@ -54,7 +54,7 b' KBINT = False'
54 USE_TK = False
54 USE_TK = False
55
55
56 # ID for the main thread, used for cross-thread exceptions
56 # ID for the main thread, used for cross-thread exceptions
57 MAIN_THREAD_ID = None
57 MAIN_THREAD_ID = thread.get_ident()
58
58
59 # Tag when runcode() is active, for exception handling
59 # Tag when runcode() is active, for exception handling
60 CODE_RUN = None
60 CODE_RUN = None
@@ -203,7 +203,7 b' class IPShellEmbed:'
203 # Set global subsystems (display,completions) to our values
203 # Set global subsystems (display,completions) to our values
204 sys.displayhook = self.sys_displayhook_embed
204 sys.displayhook = self.sys_displayhook_embed
205 if self.IP.has_readline:
205 if self.IP.has_readline:
206 self.IP.readline.set_completer(self.IP.Completer.complete)
206 self.IP.set_completer()
207
207
208 if self.banner and header:
208 if self.banner and header:
209 format = '%s\n%s\n'
209 format = '%s\n%s\n'
@@ -312,18 +312,6 b' else:'
312 KBINT = True
312 KBINT = True
313
313
314
314
315 def _set_main_thread_id():
316 """Ugly hack to find the main thread's ID.
317 """
318 global MAIN_THREAD_ID
319 for tid, tobj in threading._active.items():
320 # There must be a better way to do this than looking at the str() for
321 # each thread object...
322 if 'MainThread' in str(tobj):
323 #print 'main tid:',tid # dbg
324 MAIN_THREAD_ID = tid
325 break
326
327 class MTInteractiveShell(InteractiveShell):
315 class MTInteractiveShell(InteractiveShell):
328 """Simple multi-threaded shell."""
316 """Simple multi-threaded shell."""
329
317
@@ -351,6 +339,9 b' class MTInteractiveShell(InteractiveShell):'
351 # A queue to hold the code to be executed. A scalar variable is NOT
339 # A queue to hold the code to be executed. A scalar variable is NOT
352 # enough, because uses like macros cause reentrancy.
340 # enough, because uses like macros cause reentrancy.
353 self.code_queue = Queue.Queue()
341 self.code_queue = Queue.Queue()
342
343 # Track once we properly install our special sigint handler
344 self._sigint_handler_not_ready = True
354
345
355 # Stuff to do at closing time
346 # Stuff to do at closing time
356 self._kill = False
347 self._kill = False
@@ -406,7 +397,6 b' class MTInteractiveShell(InteractiveShell):'
406
397
407 Multithreaded wrapper around IPython's runcode()."""
398 Multithreaded wrapper around IPython's runcode()."""
408
399
409
410 global CODE_RUN
400 global CODE_RUN
411
401
412 # Exceptions need to be raised differently depending on which thread is
402 # Exceptions need to be raised differently depending on which thread is
@@ -423,14 +413,18 b' class MTInteractiveShell(InteractiveShell):'
423 tokill()
413 tokill()
424 print >>Term.cout, 'Done.'
414 print >>Term.cout, 'Done.'
425
415
426 # Install sigint handler. It feels stupid to do this on every single
416 # Install sigint handler. It feels stupid to test this on every single
427 # pass
417 # pass. At least we keep track of having done it before... We use a
428 try:
418 # negative variable so we don't have to call 'not' every time
429 signal(SIGINT,sigint_handler)
419 if self._sigint_handler_not_ready:
430 except SystemError:
420 # Try only once...
431 # This happens under Windows, which seems to have all sorts
421 self._sigint_handler_not_ready = False
432 # of problems with signal handling. Oh well...
422 try:
433 pass
423 signal(SIGINT,sigint_handler)
424 except SystemError:
425 # This happens under Windows, which seems to have all sorts
426 # of problems with signal handling. Oh well...
427 pass
434
428
435 # Flush queue of pending code by calling the run methood of the parent
429 # Flush queue of pending code by calling the run methood of the parent
436 # class with all items which may be in the queue.
430 # class with all items which may be in the queue.
@@ -681,10 +675,6 b' class IPThread(threading.Thread):'
681 self.IP.mainloop(self._banner)
675 self.IP.mainloop(self._banner)
682 self.IP.kill()
676 self.IP.kill()
683
677
684 def start(self):
685 threading.Thread.start(self)
686 _set_main_thread_id()
687
688 class IPShellGTK(IPThread):
678 class IPShellGTK(IPThread):
689 """Run a gtk mainloop() in a separate thread.
679 """Run a gtk mainloop() in a separate thread.
690
680
@@ -855,7 +845,6 b' class IPShellWX(IPThread):'
855 self.agent.StartWork()
845 self.agent.StartWork()
856 return True
846 return True
857
847
858 _set_main_thread_id()
859 self.app = App(redirect=False)
848 self.app = App(redirect=False)
860 self.wx_mainloop(self.app)
849 self.wx_mainloop(self.app)
861 self.join()
850 self.join()
@@ -1001,8 +990,8 b' class IPShellQt4(IPThread):'
1001 return result
990 return result
1002
991
1003
992
1004 # A set of matplotlib public IPython shell classes, for single-threaded
993 # A set of matplotlib public IPython shell classes, for single-threaded (Tk*
1005 # (Tk* and FLTK* backends) and multithreaded (GTK* and WX* backends) use.
994 # and FLTK*) and multithreaded (GTK*, WX* and Qt*) backends to use.
1006 def _load_pylab(user_ns):
995 def _load_pylab(user_ns):
1007 """Allow users to disable pulling all of pylab into the top-level
996 """Allow users to disable pulling all of pylab into the top-level
1008 namespace.
997 namespace.
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 2207 2007-04-05 02:07:24Z fperez $
9 $Id: iplib.py 2221 2007-04-06 02:58:37Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -882,6 +882,10 b' class InteractiveShell(object,Magic):'
882 self.Completer.__class__)
882 self.Completer.__class__)
883 self.Completer.matchers.insert(pos,newcomp)
883 self.Completer.matchers.insert(pos,newcomp)
884
884
885 def set_completer(self):
886 """reset readline's completer to be our own."""
887 self.readline.set_completer(self.Completer.complete)
888
885 def _get_call_pdb(self):
889 def _get_call_pdb(self):
886 return self._call_pdb
890 return self._call_pdb
887
891
@@ -1311,7 +1315,7 b' want to merge them back into the new files.""" % locals()'
1311 self.readline = readline
1315 self.readline = readline
1312 # save this in sys so embedded copies can restore it properly
1316 # save this in sys so embedded copies can restore it properly
1313 sys.ipcompleter = self.Completer.complete
1317 sys.ipcompleter = self.Completer.complete
1314 readline.set_completer(self.Completer.complete)
1318 self.set_completer()
1315
1319
1316 # Configure readline according to user's prefs
1320 # Configure readline according to user's prefs
1317 for rlcommand in self.rc.readline_parse_and_bind:
1321 for rlcommand in self.rc.readline_parse_and_bind:
@@ -1488,7 +1492,7 b' want to merge them back into the new files.""" % locals()'
1488 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
1492 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
1489 if self.InteractiveTB.call_pdb and self.has_readline:
1493 if self.InteractiveTB.call_pdb and self.has_readline:
1490 # pdb mucks up readline, fix it back
1494 # pdb mucks up readline, fix it back
1491 self.readline.set_completer(self.Completer.complete)
1495 self.set_completer()
1492
1496
1493 def mainloop(self,banner=None):
1497 def mainloop(self,banner=None):
1494 """Creates the local namespace and starts the mainloop.
1498 """Creates the local namespace and starts the mainloop.
@@ -1979,14 +1983,17 b' want to merge them back into the new files.""" % locals()'
1979 continuation in a sequence of inputs.
1983 continuation in a sequence of inputs.
1980 """
1984 """
1981
1985
1986 # Code run by the user may have modified the readline completer state.
1987 # We must ensure that our completer is back in place.
1988 self.set_completer()
1989
1982 try:
1990 try:
1983 line = raw_input_original(prompt).decode(sys.stdin.encoding)
1991 line = raw_input_original(prompt).decode(sys.stdin.encoding)
1984 #line = raw_input_original(prompt)
1985 except ValueError:
1992 except ValueError:
1986 warn("\n********\nYou or a %run:ed script called sys.stdin.close() or sys.stdout.close()!\nExiting IPython!")
1993 warn("\n********\nYou or a %run:ed script called sys.stdin.close()"
1994 " or sys.stdout.close()!\nExiting IPython!")
1987 self.exit_now = True
1995 self.exit_now = True
1988 return ""
1996 return ""
1989
1990
1997
1991 # Try to be reasonably smart about not re-indenting pasted input more
1998 # Try to be reasonably smart about not re-indenting pasted input more
1992 # than necessary. We do this by trimming out the auto-indent initial
1999 # than necessary. We do this by trimming out the auto-indent initial
@@ -2174,14 +2181,9 b' want to merge them back into the new files.""" % locals()'
2174 # It also allows users to assign to either alias or magic names true
2181 # It also allows users to assign to either alias or magic names true
2175 # python variables (the magic/alias systems always take second seat to
2182 # python variables (the magic/alias systems always take second seat to
2176 # true python code).
2183 # true python code).
2177 #
2184 if theRest and theRest[0] in '!=()':
2178 # We also go to direct execution if there's a binary operator in there,
2179 # so users get the regular exception. Note that '-' is NOT included,
2180 # since it is also a unary operator ('+' can also be used as unary, but
2181 # in practice it rarely is).
2182 if theRest and theRest[0] in '!=()<>+*/%^&|':
2183 return self.handle_normal(line,continue_prompt)
2185 return self.handle_normal(line,continue_prompt)
2184
2186
2185 if oinfo is None:
2187 if oinfo is None:
2186 # let's try to ensure that _oinfo is ONLY called when autocall is
2188 # let's try to ensure that _oinfo is ONLY called when autocall is
2187 # on. Since it has inevitable potential side effects, at least
2189 # on. Since it has inevitable potential side effects, at least
@@ -1,3 +1,25 b''
1 2007-04-05 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/Shell.py (MAIN_THREAD_ID): get rid of my stupid hack to
4 find the main thread id and use the proper API call. Thanks to
5 Stefan for the fix.
6
7 * test/test_prefilter.py (esc_handler_tests): udpate one of Dan's
8 unit tests to reflect fixed ticket #52, and add more tests sent by
9 him.
10
11 * IPython/iplib.py (raw_input): restore the readline completer
12 state on every input, in case third-party code messed it up.
13 (_prefilter): revert recent addition of early-escape checks which
14 prevent many valid alias calls from working.
15
16 * IPython/Shell.py (MTInteractiveShell.runcode): add a tracking
17 flag for sigint handler so we don't run a full signal() call on
18 each runcode access.
19
20 * IPython/Magic.py (magic_whos): small improvement to diagnostic
21 message.
22
1 2007-04-04 Fernando Perez <Fernando.Perez@colorado.edu>
23 2007-04-04 Fernando Perez <Fernando.Perez@colorado.edu>
2
24
3 * IPython/Shell.py (sigint_handler): I *THINK* I finally got
25 * IPython/Shell.py (sigint_handler): I *THINK* I finally got
@@ -145,8 +145,15 b' esc_handler_tests = ['
145 ( '?thing', handle_help, ),
145 ( '?thing', handle_help, ),
146 ( 'thing?', handle_help ), # '?' can trail...
146 ( 'thing?', handle_help ), # '?' can trail...
147 ( 'thing!', handle_normal), # but only '?' can trail
147 ( 'thing!', handle_normal), # but only '?' can trail
148 ( '!thing?', handle_help), # trailing '?' wins if more than one
149 ( ' ?thing', handle_help), # ignore leading whitespace
148 ( ' ?thing', handle_help), # ignore leading whitespace
149 # Trailing qmark combos. Odd special cases abound
150 ( '!thing?', handle_shell_escape), # trailing '?' loses to shell esc
151 ( '!thing ?', handle_shell_escape),
152 ( '!!thing?', handle_shell_escape),
153 ( '%cmd?', handle_help),
154 ( '/cmd?', handle_help),
155 ( ';cmd?', handle_help),
156 ( ',cmd?', handle_help),
150 ( '!ls', handle_shell_escape ),
157 ( '!ls', handle_shell_escape ),
151 ( '%magic', handle_magic),
158 ( '%magic', handle_magic),
152 # Possibly, add test for /,; once those are unhooked from %autocall
159 # Possibly, add test for /,; once those are unhooked from %autocall
General Comments 0
You need to be logged in to leave comments. Login now