Fix importing of modules from the SConscript directory (Anthony Roach)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 16 Apr 2002 12:30:36 +0000 (12:30 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 16 Apr 2002 12:30:36 +0000 (12:30 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@334 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Script/SConscript.py
test/SConscript.py

index b14aa57a4c7d5f1608ae23347b542ab8a8d9c2b9..019b8e704ae1f6c14b9d6c1a334adc78417cfbd3 100644 (file)
@@ -100,6 +100,9 @@ RELEASE 0.07 -
   - Change the -U option to -D.  Make a new -U that builds just the
     targets from the local SConscript file.
 
+  - Fixed use of sys.path so Python modules can be imported from
+    the SConscript directory.
+
 
 
 RELEASE 0.06 - Thu, 28 Mar 2002 01:24:29 -0600
index eb1a13e9bbabc9d24b2b5ca00af9858426c9f013..f30652d8dfa3f0d3a6dd30605a496776279d4276 100644 (file)
@@ -39,6 +39,7 @@ import SCons.Node.FS
 import SCons.Util
 
 import os
+import os.path
 import string
 import sys
 
@@ -105,8 +106,8 @@ def SConscript(script, exports=[]):
 
     # push:
     stack.append(Frame(exports))
-
     old_dir = None
+    old_sys_path = sys.path
     try:
         # call:
         if script == "-":
@@ -120,11 +121,18 @@ def SConscript(script, exports=[]):
                 if sconscript_chdir:
                     old_dir = os.getcwd()
                     os.chdir(str(script.dir))
+
+                # prepend the SConscript directory to sys.path so
+                # that Python modules in the SConscript directory can
+                # be easily imported.
+                sys.path = [os.path.abspath(str(script.dir))] + sys.path
+
                 exec file in stack[-1].globals
             else:
                 sys.stderr.write("Ignoring missing SConscript '%s'\n" % script.path)
     finally:
         # pop:
+        sys.path = old_sys_path
         frame = stack.pop()
         SCons.Node.FS.default_fs.chdir(frame.prev_dir)
         if old_dir:
index d9c7748c5b0b95cdef99d04e81badcc6527fb669..0062be63cacbd305a3156ff0baedf2488482646c 100644 (file)
@@ -28,8 +28,14 @@ import TestSCons
 
 test = TestSCons.TestSCons()
 
+test.write('foo.py', """
+foo = 4""")
+
 test.write('SConstruct', """
 import os
+import foo
+
+assert foo.foo == 4
 
 print "SConstruct", os.getcwd()
 SConscript('SConscript')