##// END OF EJS Templates
Make glob expansion default in %run magic command
Takafumi Arakaki -
Show More
@@ -347,7 +347,7 b' python-profiler package from non-free.""")'
347 """Run the named file inside IPython as a program.
347 """Run the named file inside IPython as a program.
348
348
349 Usage:\\
349 Usage:\\
350 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options]] file [args]
350 %run [-n -i -t [-N<N>] -d [-b<N>] -p [profile options] -G] file [args]
351
351
352 Parameters after the filename are passed as command-line arguments to
352 Parameters after the filename are passed as command-line arguments to
353 the program (put in sys.argv). Then, control returns to IPython's
353 the program (put in sys.argv). Then, control returns to IPython's
@@ -368,6 +368,13 b' python-profiler package from non-free.""")'
368 and sys.argv). This allows for very convenient loading of code for
368 and sys.argv). This allows for very convenient loading of code for
369 interactive work, while giving each program a 'clean sheet' to run in.
369 interactive work, while giving each program a 'clean sheet' to run in.
370
370
371 Arguments are expanded using shell-like glob match. Patterns
372 '*', '?', '[seq]' and '[!seq]' can be used. Additionally,
373 tilde '~' will be expanded into user's home directory. Unlike
374 real shells, quotation does not suppress expansions. Use back
375 slash (e.g., '\\*') to suppress expansions. To completely
376 disable these expansions, you can use -G flag.
377
371 Options:
378 Options:
372
379
373 -n: __name__ is NOT set to '__main__', but to the running file's name
380 -n: __name__ is NOT set to '__main__', but to the running file's name
@@ -462,14 +469,13 b' python-profiler package from non-free.""")'
462
469
463 will run the example module.
470 will run the example module.
464
471
465 -g: enables shell-like glob expansion of arguments to the script
472 -G: disable shell-like glob expansion of arguments.
466 to run. Patterns '*', '?', '[seq]' and '[!seq]' can be used.
467
473
468 """
474 """
469
475
470 # get arguments and set sys.argv for program to be run.
476 # get arguments and set sys.argv for program to be run.
471 opts, arg_lst = self.parse_options(parameter_s,
477 opts, arg_lst = self.parse_options(parameter_s,
472 'nidtN:b:pD:l:rs:T:em:g',
478 'nidtN:b:pD:l:rs:T:em:G',
473 mode='list', list_all=1)
479 mode='list', list_all=1)
474 if "m" in opts:
480 if "m" in opts:
475 modulename = opts["m"][0]
481 modulename = opts["m"][0]
@@ -503,12 +509,11 b' python-profiler package from non-free.""")'
503 # were run from a system shell.
509 # were run from a system shell.
504 save_argv = sys.argv # save it for later restoring
510 save_argv = sys.argv # save it for later restoring
505
511
506 # simulate shell expansion on arguments, at least tilde expansion
512 if 'G' in opts:
507 args = [ os.path.expanduser(a) for a in arg_lst[1:] ]
513 args = arg_lst[1:]
508
514 else:
509 # glob expansion
515 # tilde and glob expansion
510 if 'g' in opts:
516 args = globlist(map(os.path.expanduser, arg_lst[1:]))
511 args = globlist(args)
512
517
513 sys.argv = [filename] + args # put in the proper filename
518 sys.argv = [filename] + args # put in the proper filename
514 # protect sys.argv from potential unicode strings on Python 2:
519 # protect sys.argv from potential unicode strings on Python 2:
General Comments 0
You need to be logged in to leave comments. Login now