diff options
author | grbd <garlicbready@googlemail.com> | 2017-06-27 22:24:55 +0100 |
---|---|---|
committer | grbd <garlicbready@googlemail.com> | 2017-06-27 22:24:55 +0100 |
commit | 470c08f9d22bfe19cf053a4c5276d5bfec2318af (patch) | |
tree | 1e620107f8be3b864ee4af3092bc0912046d9afe | |
parent | 22451bf012d407b9f4ade38dffe34e5b10f44725 (diff) | |
download | scons-470c08f9d22bfe19cf053a4c5276d5bfec2318af.tar.gz |
Added support for relative imports within tools for python3 and tests for relative imports
11 files changed, 96 insertions, 1 deletions
diff --git a/src/engine/SCons/Tool/__init__.py b/src/engine/SCons/Tool/__init__.py index e5b4b05a..80a16f5a 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 00000000..6156929b --- /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 00000000..4c9a7bc4 --- /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 00000000..e65f8cd1 --- /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 00000000..463baee3 --- /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 00000000..e69de29b --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/TestTool1_2_2/sconstest.skip 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 00000000..8bd698f8 --- /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 00000000..e69de29b --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/TestTool1_2/sconstest.skip 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 00000000..d5510d2c --- /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 00000000..e69de29b --- /dev/null +++ b/test/toolpath/relative_import/image/tools/TestTool1/sconstest.skip diff --git a/test/toolpath/relative_import/relative_import.py b/test/toolpath/relative_import/relative_import.py new file mode 100644 index 00000000..8fa2f62c --- /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:
|