From fe8669695dad03dfe0c9e8b322d3ec86d8301229 Mon Sep 17 00:00:00 2001 From: grbd Date: Tue, 27 Jun 2017 22:24:55 +0100 Subject: Added support for relative imports within tools for python3 and tests for relative imports --- src/engine/SCons/Tool/__init__.py | 2 +- test/toolpath/relative_import/image/SConstruct | 10 ++++ .../image/tools/TestTool1/TestTool1_1.py | 4 ++ .../tools/TestTool1/TestTool1_2/TestTool1_2_1.py | 4 ++ .../TestTool1_2/TestTool1_2_2/__init__.py | 4 ++ .../TestTool1_2/TestTool1_2_2/sconstest.skip | 0 .../image/tools/TestTool1/TestTool1_2/__init__.py | 11 +++++ .../tools/TestTool1/TestTool1_2/sconstest.skip | 0 .../image/tools/TestTool1/__init__.py | 9 ++++ .../image/tools/TestTool1/sconstest.skip | 0 test/toolpath/relative_import/relative_import.py | 53 ++++++++++++++++++++++ 11 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 test/toolpath/relative_import/image/SConstruct create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_1.py create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_1.py create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/__init__.py create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/sconstest.skip create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/__init__.py create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/sconstest.skip create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/__init__.py create mode 100644 test/toolpath/relative_import/image/tools/TestTool1/sconstest.skip create mode 100644 test/toolpath/relative_import/relative_import.py diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index e5b4b05..80a16f5 100644 --- a/src/engine/SCons/Tool/__init__.py +++ b/src/engine/SCons/Tool/__init__.py @@ -225,7 +225,7 @@ class Tool(object): # Not sure what to do in the case that there already # exists sys.modules[self.name] but the source file is # different.. ? - spec.loader.exec_module(module) + module = spec.loader.load_module(spec.name) sys.modules[found_name] = module if add_to_scons_tools_namespace: diff --git a/test/toolpath/relative_import/image/SConstruct b/test/toolpath/relative_import/image/SConstruct new file mode 100644 index 0000000..6156929 --- /dev/null +++ b/test/toolpath/relative_import/image/SConstruct @@ -0,0 +1,10 @@ +env = Environment(tools=['TestTool1', 'TestTool1.TestTool1_2'], toolpath=['tools']) + +# Test a relative import within the root of the tools directory +print("env['TestTool1'] =", env.get('TestTool1')) +print("env['TestTool1_1'] =", env.get('TestTool1_1')) + +# Test a relative import within a sub dir +print("env['TestTool1_2'] =", env.get('TestTool1_2')) +print("env['TestTool1_2_1'] =", env.get('TestTool1_2_1')) +print("env['TestTool1_2_2'] =", env.get('TestTool1_2_2')) diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_1.py b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_1.py new file mode 100644 index 0000000..4c9a7bc --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_1.py @@ -0,0 +1,4 @@ +def generate(env): + env['TestTool1_1'] = 1 +def exists(env): + return 1 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_1.py b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_1.py new file mode 100644 index 0000000..e65f8cd --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_1.py @@ -0,0 +1,4 @@ +def generate(env): + env['TestTool1_2_1'] = 1 +def exists(env): + return 1 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/__init__.py b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/__init__.py new file mode 100644 index 0000000..463baee --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/__init__.py @@ -0,0 +1,4 @@ +def generate(env): + env['TestTool1_2_2'] = 1 +def exists(env): + return 1 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/sconstest.skip b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/__init__.py b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/__init__.py new file mode 100644 index 0000000..8bd698f --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/__init__.py @@ -0,0 +1,11 @@ +from . import TestTool1_2_1 +from . import TestTool1_2_2 + +def generate(env): + env['TestTool1_2'] = 1 + TestTool1_2_1.generate(env) + TestTool1_2_2.generate(env) +def exists(env): + TestTool1_2_1.exists(env) + TestTool1_2_2.exists(env) + return 1 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/sconstest.skip b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/__init__.py b/test/toolpath/relative_import/image/tools/TestTool1/__init__.py new file mode 100644 index 0000000..d5510d2 --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/__init__.py @@ -0,0 +1,9 @@ +from . import TestTool1_1 + +def generate(env): + env['TestTool1'] = 1 + # Include another tool within the same directory + TestTool1_1.generate(env) +def exists(env): + TestTool1_1.exists(env) + return 1 diff --git a/test/toolpath/relative_import/image/tools/TestTool1/sconstest.skip b/test/toolpath/relative_import/image/tools/TestTool1/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/toolpath/relative_import/relative_import.py b/test/toolpath/relative_import/relative_import.py new file mode 100644 index 0000000..8fa2f62 --- /dev/null +++ b/test/toolpath/relative_import/relative_import.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os.path +import TestSCons + +test = TestSCons.TestSCons() + +test.dir_fixture('image') + +test.run(arguments = '.', stdout = """\ +scons: Reading SConscript files ... +env['TestTool1'] = 1 +env['TestTool1_1'] = 1 +env['TestTool1_2'] = 1 +env['TestTool1_2_1'] = 1 +env['TestTool1_2_2'] = 1 +scons: done reading SConscript files. +scons: Building targets ... +scons: `.' is up to date. +scons: done building targets. +""") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: -- cgit v0.12