Allow importing local files from Tools found on a toolpath. (Chad Austin)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 7 Oct 2004 19:41:27 +0000 (19:41 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Thu, 7 Oct 2004 19:41:27 +0000 (19:41 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1117 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Tool/__init__.py
test/toolpath.py

index 870d95b600107261d6d5e2ec5a86020c9a7b3788..a7f606f320a7b567a7f863483519263a28428cc8 100644 (file)
@@ -15,6 +15,9 @@ RELEASE 0.97 - XXX
   - Allow Help() to be called multiple times, appending to the help
     text each call.
 
+  - Allow Tools found on a toolpath to import Python modules from
+    their local directory.
+
   From Steve Christensen:
 
   - Handle exceptions from Python functions as build actions.
index 2adaacb486fef994dcc5c3cc6d8300d5222918f3..71ef082874363a72258bd28e12f644023582df19 100644 (file)
@@ -69,19 +69,26 @@ class ToolSpec:
 def Tool(name, toolpath=[], **kw):
     "Select a canned Tool specification, optionally searching in toolpath."
 
+    oldpythonpath = sys.path
+    sys.path = toolpath + sys.path
+
     try:
-        file, path, desc = imp.find_module(name, toolpath)
         try:
-            module = imp.load_module(name, file, path, desc)
-            spec = apply(ToolSpec, (name,), kw)
-            spec.generate = module.generate
-            spec.exists = module.exists
-            return spec
-        finally:
-            if file:
-                file.close()
-    except ImportError, e:
-        pass
+            file, path, desc = imp.find_module(name, toolpath)
+            try:
+                module = imp.load_module(name, file, path, desc)
+                spec = apply(ToolSpec, (name,), kw)
+                spec.generate = module.generate
+                spec.exists = module.exists
+                return spec
+            finally:
+                if file:
+                    file.close()
+        except ImportError, e:
+            pass
+    finally:
+        sys.path = oldpythonpath
+
     
     full_name = 'SCons.Tool.' + name
     if not sys.modules.has_key(full_name):
index da9f585a8df9a9e9dbf1c87d9e941598dd041a21..797f34528d58ce8c270e26b6c34ca73f4aeb4c7d 100644 (file)
@@ -98,11 +98,16 @@ def exists(env):
 
 test.subdir('tools')
 
+test.write(['tools', 'Common.py'], r"""\
+One = 1
+""")
+
 test.write(['tools', 'SCCS.py'], r"""\
+import Common
 def generate(env):
-    env['TOOL_SCCS2'] = 1
+    env['TOOL_SCCS2'] = Common.One
 def exists(env):
-    return 1
+    return Common.One
 """)
 
 test.write(['tools', 'bar.py'], r"""\