From ef5302e42b97cc6afabc1cb8390fe3d683dc5d81 Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Thu, 7 Oct 2004 19:41:27 +0000 Subject: Allow importing local files from Tools found on a toolpath. (Chad Austin) --- 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 870d95b..a7f606f 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 2adaacb..71ef082 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 da9f585..797f345 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"""\ -- cgit v0.12