在site-packages\spyderlib目录中搜索关键字%run后,我找到了构造%run命令的方法(在site-packages\spyderlib\plugins\ipythonconsole.py中):
def run_script_in_current_client(self, filename, wdir, args, debug):
"""Run script in current client, if any"""
norm = lambda text: remove_backslashes(to_text_string(text))
client = self.get_current_client()
if client is not None:
# Internal kernels, use runfile
if client.kernel_widget_id is not None:
line = "%s('%s'" % ('debugfile' if debug else 'runfile',
norm(filename))
if args:
line += ", args='%s'" % norm(args)
if wdir:
line += ", wdir='%s'" % norm(wdir)
line += ")"
else: # External kernels, use %run
line = "%run "
if debug:
line += "-d "
line += "\"%s\"" % to_text_string(filename)
if args:
line += " %s" % norm(args)
self.execute_python_code(line)
self.visibility_changed(True)
self.raise_()
else:
#XXX: not sure it can really happen
QMessageBox.warning(self, _('Warning'),
_("No IPython console is currently available to run <b>%s</b>."
"<br><br>Please open a new one and try again."
) % osp.basename(filename), QMessageBox.Ok)
我在else: # External kernels, use %run之后添加了以下代码转换路径
# ----added to remap local dir to remote dir-------
localpath = "Z:\wk"
remotepath = "/mnt/sdb1/wk"
if localpath in filename:
# convert path to linux path
filename = filename.replace(localpath, remotepath)
filename = filename.replace("\\", "/")
# ----- END mod
现在当我按下 F5 时它会在远程机器上运行文件。
我在Spyder 2.3.9 上,samba 共享映射到 z: 驱动器。