From e244f5a61a2ea56884267842b195517224a52f2b 2006-12-12 21:51:54 From: vivainio Date: 2006-12-12 21:51:54 Subject: [PATCH] implement %run myscript.ipy --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 4e84f3b..4c8fc49 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1962 2006-12-05 21:08:50Z vivainio $""" +$Id: Magic.py 1981 2006-12-12 21:51:54Z vivainio $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -1375,7 +1375,7 @@ Currently the magic system has the following functions:\n""" Usage:\\ %run [-n -i -t [-N] -d [-b] -p [profile options]] 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 prompt. @@ -1472,7 +1472,12 @@ Currently the magic system has the following functions:\n""" where the profiler executes them). Internally this triggers a call to %prun, see its documentation for - details on the options available specifically for profiling.""" + details on the options available specifically for profiling. + + There is one special usage for which the text above doesn't apply: + if the filename ends with .ipy, the file is run as ipython script, + just as if the commands were written on IPython prompt. + """ # 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:e', @@ -1488,6 +1493,10 @@ Currently the magic system has the following functions:\n""" error(msg) return + if filename.lower().endswith('.ipy'): + self.api.runlines(open(filename).read()) + return + # Control the response to exit() calls made by the script being run exit_ignore = opts.has_key('e') diff --git a/doc/ChangeLog b/doc/ChangeLog index 655efec..9ac9bc8 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -7,6 +7,10 @@ * UserConfig/ipy_user_conf.py, UserConfig/ipythonrc: Add deprecation note to ipythonrc and a url to wiki in ipy_user_conf.py + + * Magic.py (%run): %run myscript.ipy now runs myscript.ipy + as if it was typed on IPython command prompt, i.e. + as IPython script. 2006-12-08 Ville Vainio diff --git a/doc/examples/seteditor.py b/doc/examples/seteditor.py new file mode 100755 index 0000000..d9227cf --- /dev/null +++ b/doc/examples/seteditor.py @@ -0,0 +1,15 @@ +import os + + +editor = r'q:/opt/np/notepad++.exe' + + +e = os.environ + +e['EDITOR'] = editor +e['VISUAL'] = editor + + + + +