From e367faeca7bbbf6498dc5b5205dd2e1f5fd25ca3 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 7 Oct 2004 19:41:27 +0000 Subject: [PATCH] Allow importing local files from Tools found on a toolpath. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1117 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 3 +++ src/engine/SCons/Tool/__init__.py | 29 ++++++++++++++++++----------- test/toolpath.py | 9 +++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 870d95b6..a7f606f3 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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. diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index 2adaacb4..71ef0828 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -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): diff --git a/test/toolpath.py b/test/toolpath.py index da9f585a..797f3452 100644 --- a/test/toolpath.py +++ b/test/toolpath.py @@ -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"""\ -- 2.26.2