From daef07e0c907baab65334cf457f9922b06b3998f 2007-09-07 18:19:42 From: vivainio Date: 2007-09-07 18:19:42 Subject: [PATCH] ipykit pylaunchers do .ipy now --- diff --git a/IPython/Extensions/ipy_kitcfg.py b/IPython/Extensions/ipy_kitcfg.py index cc53c87..da77bf7 100644 --- a/IPython/Extensions/ipy_kitcfg.py +++ b/IPython/Extensions/ipy_kitcfg.py @@ -9,8 +9,10 @@ def pylaunchers(): This is useful if you want to invoke .py scripts from ipykit session, just adding .py files in PATH does not work without file association. + .ipy files will be run like macros. + """ - fs = glob.glob('*.py*') + fs = glob.glob('*.?py*') for f in fs: l = PyLauncher(f) n = os.path.splitext(f)[0] diff --git a/IPython/Extensions/ipy_rehashdir.py b/IPython/Extensions/ipy_rehashdir.py index 6e4f44b..54b6702 100644 --- a/IPython/Extensions/ipy_rehashdir.py +++ b/IPython/Extensions/ipy_rehashdir.py @@ -24,10 +24,17 @@ import os,re,fnmatch,sys def selflaunch(ip,line): """ Launch python script with 'this' interpreter - e.g. d:\foo\ipython.exe a.py + e.g. d:\foo\ipykit.exe a.py """ - cmd = sys.executable + ' ' + line.split(None,1)[1] + + tup = line.split(None,1) + if len(tup) == 1: + print "Launching nested ipython session" + os.system(sys.executable) + return + + cmd = sys.executable + ' ' + tup[1] print ">",cmd os.system(cmd) @@ -41,9 +48,13 @@ class PyLauncher: def __init__(self,script): self.script = os.path.abspath(script) def __call__(self, ip, line): - selflaunch("py " + self.script + ' ' + line) + if self.script.endswith('.ipy'): + ip.runlines(open(self.script).read()) + else: + selflaunch("py " + self.script + ' ' + line) def __repr__(self): return 'PyLauncher("%s")' % self.script + def rehashdir_f(self,arg): """ Add executables in all specified dirs to alias table