Show More
@@ -1,7 +1,7 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """sys.excepthook for IPython itself, leaves a detailed report on disk. |
|
3 | 3 | |
|
4 |
$Id: CrashHandler.py 132 |
|
|
4 | $Id: CrashHandler.py 1326 2006-05-25 02:07:11Z fperez $""" | |
|
5 | 5 | |
|
6 | 6 | #***************************************************************************** |
|
7 | 7 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
@@ -87,7 +87,7 b' If you want to do it now, the following command will work (under Unix):' | |||
|
87 | 87 | mail -s 'IPython Crash Report' $self.mailto < $self.report_name |
|
88 | 88 | |
|
89 | 89 | To ensure accurate tracking of this issue, please file a report about it at: |
|
90 | http://www.scipy.net/roundup/ipython (IPython's online bug tracker). | |
|
90 | http://projects.scipy.org/ipython/ipython/report | |
|
91 | 91 | """) |
|
92 | 92 | print >> sys.stderr, msg |
|
93 | 93 |
@@ -4,7 +4,7 b'' | |||
|
4 | 4 | All the matplotlib support code was co-developed with John Hunter, |
|
5 | 5 | matplotlib's author. |
|
6 | 6 | |
|
7 |
$Id: Shell.py 13 |
|
|
7 | $Id: Shell.py 1326 2006-05-25 02:07:11Z fperez $""" | |
|
8 | 8 | |
|
9 | 9 | #***************************************************************************** |
|
10 | 10 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
@@ -51,7 +51,8 b' class IPShell:' | |||
|
51 | 51 | |
|
52 | 52 | def __init__(self,argv=None,user_ns=None,user_global_ns=None, |
|
53 | 53 | debug=1,shell_class=InteractiveShell): |
|
54 |
self.IP = make_IPython(argv,user_ns=user_ns, |
|
|
54 | self.IP = make_IPython(argv,user_ns=user_ns, | |
|
55 | user_global_ns=user_global_ns, | |
|
55 | 56 | debug=debug,shell_class=shell_class) |
|
56 | 57 | |
|
57 | 58 | def mainloop(self,sys_exit=0,banner=None): |
@@ -112,7 +113,8 b' class IPShellEmbed:' | |||
|
112 | 113 | <cmkleffner@gmx.de> on Dec. 06/01 concerning similar uses of pyrepl, and |
|
113 | 114 | by the IDL stop/continue commands.""" |
|
114 | 115 | |
|
115 |
def __init__(self,argv=None,banner='',exit_msg=None,rc_override=None |
|
|
116 | def __init__(self,argv=None,banner='',exit_msg=None,rc_override=None, | |
|
117 | user_ns=None): | |
|
116 | 118 | """Note that argv here is a string, NOT a list.""" |
|
117 | 119 | self.set_banner(banner) |
|
118 | 120 | self.set_exit_msg(exit_msg) |
@@ -129,9 +131,9 b' class IPShellEmbed:' | |||
|
129 | 131 | except: |
|
130 | 132 | pass # not nested with IPython |
|
131 | 133 | |
|
132 | # FIXME. Passing user_ns breaks namespace handling. | |
|
133 | #self.IP = make_IPython(argv,user_ns=__main__.__dict__) | |
|
134 | self.IP = make_IPython(argv,rc_override=rc_override,embedded=True) | |
|
134 | self.IP = make_IPython(argv,rc_override=rc_override, | |
|
135 | embedded=True, | |
|
136 | user_ns=user_ns) | |
|
135 | 137 | |
|
136 | 138 | # copy our own displayhook also |
|
137 | 139 | self.sys_displayhook_embed = sys.displayhook |
@@ -387,7 +389,7 b' class MatplotlibShellBase:' | |||
|
387 | 389 | Given Python's MRO, this should be used as the FIRST class in the |
|
388 | 390 | inheritance hierarchy, so that it overrides the relevant methods.""" |
|
389 | 391 | |
|
390 | def _matplotlib_config(self,name): | |
|
392 | def _matplotlib_config(self,name,user_ns): | |
|
391 | 393 | """Return items needed to setup the user's shell with matplotlib""" |
|
392 | 394 | |
|
393 | 395 | # Initialize matplotlib to interactive mode always |
@@ -432,14 +434,8 b' class MatplotlibShellBase:' | |||
|
432 | 434 | |
|
433 | 435 | # This must be imported last in the matplotlib series, after |
|
434 | 436 | # backend/interactivity choices have been made |
|
435 | try: | |
|
436 |
|
|
|
437 | self.pylab = pylab | |
|
438 | self.pylab_name = 'pylab' | |
|
439 | except ImportError: | |
|
440 | import matplotlib.matlab as matlab | |
|
441 | self.pylab = matlab | |
|
442 | self.pylab_name = 'matlab' | |
|
437 | import matplotlib.pylab as pylab | |
|
438 | self.pylab = pylab | |
|
443 | 439 | |
|
444 | 440 | self.pylab.show._needmain = False |
|
445 | 441 | # We need to detect at runtime whether show() is called by the user. |
@@ -447,16 +443,11 b' class MatplotlibShellBase:' | |||
|
447 | 443 | self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive) |
|
448 | 444 | |
|
449 | 445 | # Build a user namespace initialized with matplotlib/matlab features. |
|
450 | user_ns = {'__name__':'__main__', | |
|
451 | '__builtins__' : __builtin__ } | |
|
446 | user_ns = IPython.ipapi.make_user_ns(user_ns) | |
|
452 | 447 | |
|
453 | # Be careful not to remove the final \n in the code string below, or | |
|
454 | # things will break badly with py22 (I think it's a python bug, 2.3 is | |
|
455 | # OK). | |
|
456 | pname = self.pylab_name # Python can't interpolate dotted var names | |
|
457 | 448 | exec ("import matplotlib\n" |
|
458 |
"import matplotlib. |
|
|
459 |
"from matplotlib. |
|
|
449 | "import matplotlib.pylab as pylab\n" | |
|
450 | "from matplotlib.pylab import *") in user_ns | |
|
460 | 451 | |
|
461 | 452 | # Build matplotlib info banner |
|
462 | 453 | b=""" |
@@ -503,7 +494,7 b' class MatplotlibShell(MatplotlibShellBase,InteractiveShell):' | |||
|
503 | 494 | |
|
504 | 495 | def __init__(self,name,usage=None,rc=Struct(opts=None,args=None), |
|
505 | 496 | user_ns=None,user_global_ns=None,**kw): |
|
506 | user_ns,b2 = self._matplotlib_config(name) | |
|
497 | user_ns,b2 = self._matplotlib_config(name,user_ns) | |
|
507 | 498 | InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns, |
|
508 | 499 | banner2=b2,**kw) |
|
509 | 500 |
@@ -61,6 +61,7 b' print "done!"' | |||
|
61 | 61 | ''' |
|
62 | 62 | |
|
63 | 63 | # stdlib imports |
|
64 | import __builtin__ | |
|
64 | 65 | import sys |
|
65 | 66 | |
|
66 | 67 | # our own |
@@ -267,7 +268,7 b' class IPApi:' | |||
|
267 | 268 | (name,cf.f_code.co_name)) |
|
268 | 269 | |
|
269 | 270 | def launch_new_instance(user_ns = None): |
|
270 |
""" |
|
|
271 | """ Make and start a new ipython instance. | |
|
271 | 272 | |
|
272 | 273 | This can be called even without having an already initialized |
|
273 | 274 | ipython session running. |
@@ -275,19 +276,53 b' def launch_new_instance(user_ns = None):' | |||
|
275 | 276 | This is also used as the egg entry point for the 'ipython' script. |
|
276 | 277 | |
|
277 | 278 | """ |
|
278 |
ses = |
|
|
279 | ses = make_session(user_ns) | |
|
279 | 280 | ses.mainloop() |
|
280 | 281 | |
|
281 | 282 | |
|
282 |
def |
|
|
283 | """ Creates, but does not launch an IPython session. | |
|
283 | def make_user_ns(user_ns = None): | |
|
284 | """Return a valid user interactive namespace. | |
|
285 | ||
|
286 | This builds a dict with the minimal information needed to operate as a | |
|
287 | valid IPython user namespace, which you can pass to the various embedding | |
|
288 | classes in ipython. | |
|
289 | """ | |
|
290 | ||
|
291 | if user_ns is None: | |
|
292 | # Set __name__ to __main__ to better match the behavior of the | |
|
293 | # normal interpreter. | |
|
294 | user_ns = {'__name__' :'__main__', | |
|
295 | '__builtins__' : __builtin__, | |
|
296 | } | |
|
297 | else: | |
|
298 | user_ns.setdefault('__name__','__main__') | |
|
299 | user_ns.setdefault('__builtins__',__builtin__) | |
|
300 | ||
|
301 | return user_ns | |
|
302 | ||
|
303 | ||
|
304 | def make_user_global_ns(ns = None): | |
|
305 | """Return a valid user global namespace. | |
|
306 | ||
|
307 | Similar to make_user_ns(), but global namespaces are really only needed in | |
|
308 | embedded applications, where there is a distinction between the user's | |
|
309 | interactive namespace and the global one where ipython is running.""" | |
|
310 | ||
|
311 | if ns is None: ns = {} | |
|
312 | return ns | |
|
313 | ||
|
314 | ||
|
315 | def make_session(user_ns = None): | |
|
316 | """Makes, but does not launch an IPython session. | |
|
284 | 317 | |
|
285 | 318 | Later on you can call obj.mainloop() on the returned object. |
|
319 | ||
|
320 | Inputs: | |
|
321 | ||
|
322 | - user_ns(None): a dict to be used as the user's namespace with initial | |
|
323 | data. | |
|
286 | 324 | |
|
287 | This should *not* be run when a session exists already. | |
|
288 | ||
|
289 | """ | |
|
290 | if user_ns is not None: | |
|
291 | user_ns["__name__"] = user_ns.get("__name__",'ipy_session') | |
|
325 | WARNING: This should *not* be run when a session exists already.""" | |
|
326 | ||
|
292 | 327 | import IPython |
|
293 |
return IPython.Shell.start(user_ns |
|
|
328 | return IPython.Shell.start(user_ns) |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||
|
6 | 6 | |
|
7 | 7 | This file contains all the classes and helper functions specific to IPython. |
|
8 | 8 | |
|
9 |
$Id: iplib.py 132 |
|
|
9 | $Id: iplib.py 1326 2006-05-25 02:07:11Z fperez $ | |
|
10 | 10 | """ |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
@@ -258,17 +258,13 b' class InteractiveShell(object,Magic):' | |||
|
258 | 258 | # that if you need to access the built-in namespace directly, you |
|
259 | 259 | # should start with "import __builtin__" (note, no 's') which will |
|
260 | 260 | # definitely give you a module. Yeah, it's somewhat confusing:-(. |
|
261 | ||
|
262 | if user_ns is None: | |
|
263 | # Set __name__ to __main__ to better match the behavior of the | |
|
264 | # normal interpreter. | |
|
265 | user_ns = {'__name__' :'__main__', | |
|
266 | '__builtins__' : __builtin__, | |
|
267 | } | |
|
268 | ||
|
269 | if user_global_ns is None: | |
|
270 | user_global_ns = {} | |
|
271 | 261 | |
|
262 | # These routines return properly built dicts as needed by the rest of | |
|
263 | # the code, and can also be used by extension writers to generate | |
|
264 | # properly initialized namespaces. | |
|
265 | user_ns = IPython.ipapi.make_user_ns(user_ns) | |
|
266 | user_global_ns = IPython.ipapi.make_user_global_ns(user_global_ns) | |
|
267 | ||
|
272 | 268 | # Assign namespaces |
|
273 | 269 | # This is the namespace where all normal user variables live |
|
274 | 270 | self.user_ns = user_ns |
@@ -1351,7 +1347,7 b' want to merge them back into the new files.""" % locals()' | |||
|
1351 | 1347 | |
|
1352 | 1348 | If an optional banner argument is given, it will override the |
|
1353 | 1349 | internally created default banner.""" |
|
1354 | ||
|
1350 | ||
|
1355 | 1351 | if self.rc.c: # Emulate Python's -c option |
|
1356 | 1352 | self.exec_init_cmd() |
|
1357 | 1353 | if banner is None: |
@@ -1,5 +1,15 b'' | |||
|
1 | 1 | 2006-05-24 Fernando Perez <Fernando.Perez@colorado.edu> |
|
2 | 2 | |
|
3 | * IPython/Shell.py (MatplotlibShellBase._matplotlib_config): Fix | |
|
4 | nasty bug which was preventing custom namespaces with -pylab, | |
|
5 | reported by M. Foord. Minor cleanup, remove old matplotlib.matlab | |
|
6 | compatibility (long gone from mpl). | |
|
7 | ||
|
8 | * IPython/ipapi.py (make_session): name change: create->make. We | |
|
9 | use make in other places (ipmaker,...), it's shorter and easier to | |
|
10 | type and say, etc. I'm trying to clean things before 0.7.2 so | |
|
11 | that I can keep things stable wrt to ipapi in the chainsaw branch. | |
|
12 | ||
|
3 | 13 | * ipython.el: fix the py-pdbtrack-input-prompt variable so that |
|
4 | 14 | python-mode recognizes our debugger mode. Add support for |
|
5 | 15 | autoindent inside (X)emacs. After a patch sent in by Jin Liu |
General Comments 0
You need to be logged in to leave comments.
Login now