diff -r 8d60c1c89105 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Fri Dec 02 21:25:39 2011 +0200 +++ b/Lib/idlelib/PyShell.py Sat Dec 03 16:57:18 2011 -0600 @@ -365,7 +365,7 @@ command = "__import__('run').main(%r)" % (del_exitf,) return [sys.executable] + w + ["-c", command, str(self.port)] - def start_subprocess(self): + def start_subprocess(self, with_cwd=False): addr = (HOST, self.port) # GUI makes several attempts to acquire socket, listens for connection for i in range(3): @@ -403,11 +403,11 @@ self.rpcclt.register("flist", self.tkconsole.flist) self.rpcclt.register("linecache", linecache) self.rpcclt.register("interp", self) - self.transfer_path() + self.transfer_path(with_cwd=with_cwd) self.poll_subprocess() return self.rpcclt - def restart_subprocess(self): + def restart_subprocess(self, with_cwd=False): if self.restarting: return self.rpcclt self.restarting = True @@ -431,7 +431,7 @@ except socket.timeout as err: self.display_no_subprocess_error() return None - self.transfer_path() + self.transfer_path(with_cwd=with_cwd) # annotate restart in shell window and mark it console.text.delete("iomark", "end-1c") if was_executing: @@ -484,12 +484,18 @@ except OSError: return - def transfer_path(self): + def transfer_path(self, with_cwd=False): + if with_cwd: # Issue 13506 + path = [''] # include Current Working Directory + path.extend(sys.path) + else: + path = sys.path + self.runcommand("""if 1: import sys as _sys _sys.path = %r del _sys - \n""" % (sys.path,)) + \n""" % (path,)) active_seq = None @@ -829,7 +835,7 @@ self.per.insertfilter(color) if use_subprocess: text.bind("<>", self.view_restart_mark) - text.bind("<>", self.restart_shell) + text.bind("<>", self.restart_shell_interactive) # self.save_stdout = sys.stdout self.save_stderr = sys.stderr @@ -979,7 +985,7 @@ self.resetoutput() if use_subprocess: nosub = '' - client = self.interp.start_subprocess() + client = self.interp.start_subprocess(with_cwd=True) if not client: self.close() return False @@ -1182,8 +1188,11 @@ self.text.see("iomark") self.text.see("restart") + def restart_shell_interactive(self, event=None): + self.interp.restart_subprocess(with_cwd=True) + def restart_shell(self, event=None): - self.interp.restart_subprocess() + self.interp.restart_subprocess(with_cwd=False) def showprompt(self): self.resetoutput()