diff options
author | Kurt B. Kaiser <kbk@shore.net> | 2003-05-31 23:44:18 (GMT) |
---|---|---|
committer | Kurt B. Kaiser <kbk@shore.net> | 2003-05-31 23:44:18 (GMT) |
commit | ce5b6d55b8594971f4935724e73393d605d390be (patch) | |
tree | e08b270fa1bb31b01e5359073877252a13f06d8c /Lib/idlelib | |
parent | ac8bd9175b8f8b93e9bb2b946d4fcf5b041475a6 (diff) | |
download | cpython-ce5b6d55b8594971f4935724e73393d605d390be.zip cpython-ce5b6d55b8594971f4935724e73393d605d390be.tar.gz cpython-ce5b6d55b8594971f4935724e73393d605d390be.tar.bz2 |
SF 745525
Excecution environment and residual shell has cwd set to the directory of
the module being run.
M ScriptBinding.py
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/ScriptBinding.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py index 0a92914..0e0f1ff 100644 --- a/Lib/idlelib/ScriptBinding.py +++ b/Lib/idlelib/ScriptBinding.py @@ -17,6 +17,7 @@ XXX GvR Redesign this interface (yet again) as follows: """ +import os import re import string import tabnanny @@ -115,7 +116,14 @@ class ScriptBinding: text.see(pos) def run_module_event(self, event): - "Check syntax, if ok run the module in the shell top level" + """Run the module after setting up the environment. + + First check the syntax. If OK, make sure the shell is active and + then transfer the arguments, set the run environment's working + directory to the directory of the module being executed and also + add that directory to its sys.path if not already included. + + """ filename = self.getfilename() if not filename: return @@ -127,6 +135,7 @@ class ScriptBinding: interp = shell.interp if PyShell.use_subprocess: shell.restart_shell() + dirname = os.path.dirname(filename) # XXX Too often this discards arguments the user just set... interp.runcommand("""if 1: _filename = %s @@ -135,8 +144,10 @@ class ScriptBinding: if (not _sys.argv or _basename(_sys.argv[0]) != _basename(_filename)): _sys.argv = [_filename] - del _filename, _sys, _basename - \n""" % `filename`) + import os as _os + _os.chdir(%s) + del _filename, _sys, _basename, _os + \n""" % (`filename`, `dirname`)) interp.prepend_syspath(filename) interp.runcode(code) |