diff options
author | Kurt B. Kaiser <kbk@shore.net> | 2003-05-15 23:23:21 (GMT) |
---|---|---|
committer | Kurt B. Kaiser <kbk@shore.net> | 2003-05-15 23:23:21 (GMT) |
commit | 11659ade1e63095ac6217b4e190c14b494ddcf82 (patch) | |
tree | c7aa7368e5dd7f2b2e7971f8cb35d0df550e59ca /Lib/idlelib | |
parent | 8f570a768fcefef5e8c9f9cf1facc4f8cdc3ef3f (diff) | |
download | cpython-11659ade1e63095ac6217b4e190c14b494ddcf82.zip cpython-11659ade1e63095ac6217b4e190c14b494ddcf82.tar.gz cpython-11659ade1e63095ac6217b4e190c14b494ddcf82.tar.bz2 |
1. When a module is run from an EditorWindow, if its directory is not in
sys.path, prepend it. This allows the module to import other modules
in the same directory. Do the same for a script run from the command
line.
2. Tweak the IDLE usage message a bit more.
SF Bug 706860 (closed)
SF Patch 686254 (reject specific solution)
SF Patch 507327 (similar)
M PyShell.py
M ScriptBinding.py
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/PyShell.py | 19 | ||||
-rw-r--r-- | Lib/idlelib/ScriptBinding.py | 5 |
2 files changed, 19 insertions, 5 deletions
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index 5f9554a..d978fc2 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -526,6 +526,18 @@ class ModifiedInterpreter(InteractiveInterpreter): linecache.cache[filename] = len(source)+1, 0, lines, filename return filename + def prepend_syspath(self, filename): + "Prepend sys.path with file's directory if not already included" + self.runcommand("""if 1: + _filename = %s + import sys as _sys + from os.path import dirname as _dirname + _dir = _dirname(_filename) + if not _dir in _sys.path: + _sys.path.insert(0, _dir) + del _filename, _sys, _dirname, _dir + \n""" % `filename`) + def showsyntaxerror(self, filename=None): """Extend base class method: Add Colorizing @@ -1069,9 +1081,9 @@ class PseudoFile: usage_msg = """\ -USAGE: idle [-deis] [-t title] [file]* - idle [-ds] [-t title] (-c cmd | -r file) [arg]* - idle [-ds] [-t title] - [arg]* +USAGE: idle [-deins] [-t title] [file]* + idle [-dns] [-t title] (-c cmd | -r file) [arg]* + idle [-dns] [-t title] - [arg]* -h print this help message and exit -n run IDLE without a subprocess (see Help/IDLE Help for details) @@ -1234,6 +1246,7 @@ def main(): if cmd: shell.interp.execsource(cmd) elif script: + shell.interp.prepend_syspath(script) shell.interp.execfile(script) root.mainloop() root.destroy() diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py index d404fc9..252526d 100644 --- a/Lib/idlelib/ScriptBinding.py +++ b/Lib/idlelib/ScriptBinding.py @@ -144,8 +144,9 @@ class ScriptBinding: if (not _sys.argv or _basename(_sys.argv[0]) != _basename(_filename)): _sys.argv = [_filename] - del _filename, _sys, _basename - \n""" % `filename`) + del _filename, _sys, _basename + \n""" % `filename`) + interp.prepend_syspath(filename) interp.runcode(code) def getfilename(self): |