From afb25d012b8a7fdd60aa284447a5e8c4c187f581 2012-07-20 23:57:26 From: Takafumi Arakaki Date: 2012-07-20 23:57:26 Subject: [PATCH] Make glob expansion default in %run magic command --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 53cf8e7..ce8e00b 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -347,7 +347,7 @@ python-profiler package from non-free.""") """Run the named file inside IPython as a program. Usage:\\ - %run [-n -i -t [-N] -d [-b] -p [profile options]] file [args] + %run [-n -i -t [-N] -d [-b] -p [profile options] -G] file [args] Parameters after the filename are passed as command-line arguments to the program (put in sys.argv). Then, control returns to IPython's @@ -368,6 +368,13 @@ python-profiler package from non-free.""") and sys.argv). This allows for very convenient loading of code for interactive work, while giving each program a 'clean sheet' to run in. + Arguments are expanded using shell-like glob match. Patterns + '*', '?', '[seq]' and '[!seq]' can be used. Additionally, + tilde '~' will be expanded into user's home directory. Unlike + real shells, quotation does not suppress expansions. Use back + slash (e.g., '\\*') to suppress expansions. To completely + disable these expansions, you can use -G flag. + Options: -n: __name__ is NOT set to '__main__', but to the running file's name @@ -462,14 +469,13 @@ python-profiler package from non-free.""") will run the example module. - -g: enables shell-like glob expansion of arguments to the script - to run. Patterns '*', '?', '[seq]' and '[!seq]' can be used. + -G: disable shell-like glob expansion of arguments. """ # get arguments and set sys.argv for program to be run. opts, arg_lst = self.parse_options(parameter_s, - 'nidtN:b:pD:l:rs:T:em:g', + 'nidtN:b:pD:l:rs:T:em:G', mode='list', list_all=1) if "m" in opts: modulename = opts["m"][0] @@ -503,12 +509,11 @@ python-profiler package from non-free.""") # were run from a system shell. save_argv = sys.argv # save it for later restoring - # simulate shell expansion on arguments, at least tilde expansion - args = [ os.path.expanduser(a) for a in arg_lst[1:] ] - - # glob expansion - if 'g' in opts: - args = globlist(args) + if 'G' in opts: + args = arg_lst[1:] + else: + # tilde and glob expansion + args = globlist(map(os.path.expanduser, arg_lst[1:])) sys.argv = [filename] + args # put in the proper filename # protect sys.argv from potential unicode strings on Python 2: