From fc67c618f8af764717704b330536514dbbd1041a 2006-01-27 16:02:38 From: vivainio Date: 2006-01-27 16:02:38 Subject: [PATCH] Provide "realistic" sys.argv for scripts run via ipython command line invocation --- diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index ce281f7..109dffd 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -6,7 +6,7 @@ Requires Python 2.1 or better. This file contains the main make_IPython() starter function. -$Id: ipmaker.py 1041 2006-01-21 09:29:14Z vivainio $""" +$Id: ipmaker.py 1086 2006-01-27 16:02:38Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -657,21 +657,24 @@ object? -> Details about 'object'. ?object also works, ?? prints more. # ipython is fully initialized, just as if they were run via %run at the # ipython prompt. This would also give them the benefit of ipython's # nice tracebacks. - + if not embedded and IP_rc.args: name_save = IP.user_ns['__name__'] IP.user_ns['__name__'] = '__main__' + # Set our own excepthook in case the user code tries to call it + # directly. This prevents triggering the IPython crash handler. + old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook + + save_argv = sys.argv[:] # save it for later restoring + sys.argv.pop(0) # the first arg is 'ipython' + try: - # Set our own excepthook in case the user code tries to call it - # directly. This prevents triggering the IPython crash handler. - old_excepthook,sys.excepthook = sys.excepthook, IP.excepthook - for run in args: - IP.safe_execfile(run,IP.user_ns) + IP.safe_execfile(args[0], IP.user_ns) finally: # Reset our crash handler in place sys.excepthook = old_excepthook - - IP.user_ns['__name__'] = name_save + sys.argv = save_argv + IP.user_ns['__name__'] = name_save msg.user_exec.release_all() if IP_rc.messages: diff --git a/doc/ChangeLog b/doc/ChangeLog index 8b6a9ed..30990aa 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,10 @@ +2006-01-27 Ville Vainio + + * ipmaker.py: Give "realistic" sys.argv for scripts (without + 'ipython' at argv[0]) executed through command line. + NOTE: this DEPRECATES calling ipython with multiple scripts + ("ipython a.py b.py c.py") + 2006-01-25 Fernando Perez * IPython/demo.py (Demo.show): Flush stdout after each block, so