[Idle-dev] CVS: idle PyShell.py,1.66,1.67 ScriptBinding.py,1.19,1.20

Kurt B. Kaiser kbk@users.sourceforge.net
Thu, 15 May 2003 16:23:23 -0700


Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv14095

Modified Files:
	PyShell.py ScriptBinding.py 
Log Message:
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


Index: PyShell.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyShell.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -r1.66 -r1.67
*** PyShell.py	15 May 2003 18:52:50 -0000	1.66
--- PyShell.py	15 May 2003 23:23:20 -0000	1.67
***************
*** 527,530 ****
--- 527,542 ----
          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
***************
*** 1070,1076 ****
  usage_msg = """\
  
! USAGE: idle  [-deis] [-t title] [file]*
!        idle  [-ds] [-t title] (-c cmd | -r file) [arg]*
!        idle  [-ds] [-t title] - [arg]*
  
    -h         print this help message and exit
--- 1082,1088 ----
  usage_msg = """\
  
! 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
***************
*** 1235,1238 ****
--- 1247,1251 ----
              shell.interp.execsource(cmd)
          elif script:
+             shell.interp.prepend_syspath(script)
              shell.interp.execfile(script)
      root.mainloop()

Index: ScriptBinding.py
===================================================================
RCS file: /cvsroot/idlefork/idle/ScriptBinding.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** ScriptBinding.py	15 May 2003 03:19:42 -0000	1.19
--- ScriptBinding.py	15 May 2003 23:23:21 -0000	1.20
***************
*** 145,150 ****
                  _basename(_sys.argv[0]) != _basename(_filename)):
                  _sys.argv = [_filename]
!                 del _filename, _sys, _basename
!                 \n""" % `filename`)
          interp.runcode(code)
  
--- 145,151 ----
                  _basename(_sys.argv[0]) != _basename(_filename)):
                  _sys.argv = [_filename]
!             del _filename, _sys, _basename
!             \n""" % `filename`)
!         interp.prepend_syspath(filename)
          interp.runcode(code)