From 1849ff611b22a55b8933dc9f05db66114e34cd14 Mon Sep 17 00:00:00 2001 From: grbd Date: Thu, 3 Aug 2017 15:53:20 +0100 Subject: Added support for a PyPackageDir function --- src/engine/SCons/Environment.py | 9 ++++ src/engine/SCons/Node/FS.py | 29 +++++++++++ src/engine/SCons/Script/__init__.py | 1 + test/Dir/PyPackageDir/PyPackageDir.py | 56 ++++++++++++++++++++++ test/Dir/PyPackageDir/image/SConstruct | 29 +++++++++++ test/Dir/PyPackageDir/image/sconstest.skip | 0 test/Dir/PyPackageDir/image/syspath/sconstest.skip | 0 .../PyPackageDir/image/syspath/submod1/__init__.py | 0 .../image/syspath/submod1/sconstest.skip | 0 .../image/syspath/submod1/submod2/__init__.py | 0 .../image/syspath/submod1/submod2/sconstest.skip | 0 .../image/syspath/submod1/submod2/testmod4.py | 0 .../PyPackageDir/image/syspath/submod1/testmod3.py | 0 .../image/syspath/testmod1/__init__.py | 0 .../image/syspath/testmod1/sconstest.skip | 0 test/Dir/PyPackageDir/image/syspath/testmod2.py | 0 test/toolpath/nested/image/SConstruct | 7 +++ test/toolpath/nested/nested.py | 3 ++ 18 files changed, 134 insertions(+) create mode 100644 test/Dir/PyPackageDir/PyPackageDir.py create mode 100644 test/Dir/PyPackageDir/image/SConstruct create mode 100644 test/Dir/PyPackageDir/image/sconstest.skip create mode 100644 test/Dir/PyPackageDir/image/syspath/sconstest.skip create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/__init__.py create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/sconstest.skip create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/submod2/__init__.py create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/submod2/sconstest.skip create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/submod2/testmod4.py create mode 100644 test/Dir/PyPackageDir/image/syspath/submod1/testmod3.py create mode 100644 test/Dir/PyPackageDir/image/syspath/testmod1/__init__.py create mode 100644 test/Dir/PyPackageDir/image/syspath/testmod1/sconstest.skip create mode 100644 test/Dir/PyPackageDir/image/syspath/testmod2.py diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index 60a45e4..480a1d6 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -1983,6 +1983,15 @@ class Base(SubstitutionEnvironment): return result return self.fs.Dir(s, *args, **kw) + def PyPackageDir(self, modulename): + s = self.subst(modulename) + if SCons.Util.is_Sequence(s): + result=[] + for e in s: + result.append(self.fs.PyPackageDir(e)) + return result + return self.fs.PyPackageDir(s) + def NoClean(self, *targets): """Tags a target so that it will not be cleaned by -c""" tlist = [] diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index d98f7d0..8c1161d 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -1390,6 +1390,35 @@ class FS(LocalFS): if not isinstance(d, SCons.Node.Node): d = self.Dir(d) self.Top.addRepository(d) + + def PyPackageDir(self, modulename): + """Locate the directory of a given python module name + + For example scons might resolve to + Windows: C:\Python27\Lib\site-packages\scons-2.5.1 + Linux: /usr/lib/scons + + This can be useful when we want to determine a toolpath based on a python module name""" + + dirpath = '' + if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] in (0,1,2,3,4)): + # Python2 Code + import imp + splitname = modulename.split('.') + srchpths = sys.path + for item in splitname: + file, path, desc = imp.find_module(item, srchpths) + if file is not None: + path = os.path.dirname(path) + srchpths = [path] + dirpath = path + else: + # Python3 Code + import importlib.util + modspec = importlib.util.find_spec(modulename) + dirpath = os.path.dirname(modspec.origin) + return self._lookup(dirpath, None, Dir, True) + def variant_dir_target_climb(self, orig, dir, tail): """Create targets in corresponding variant directories diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 3fa3a48..5bdd63e 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -337,6 +337,7 @@ GlobalDefaultEnvironmentFunctions = [ 'Local', 'ParseDepends', 'Precious', + 'PyPackageDir', 'Repository', 'Requires', 'SConsignFile', diff --git a/test/Dir/PyPackageDir/PyPackageDir.py b/test/Dir/PyPackageDir/PyPackageDir.py new file mode 100644 index 0000000..b215c7b --- /dev/null +++ b/test/Dir/PyPackageDir/PyPackageDir.py @@ -0,0 +1,56 @@ +#!/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 ... +Test identification of directory for a given python package +testmod1 +. +submod1 +submod1/submod2 +Test parameter substitution +submod1/submod2 +submod1/submod2 +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: diff --git a/test/Dir/PyPackageDir/image/SConstruct b/test/Dir/PyPackageDir/image/SConstruct new file mode 100644 index 0000000..90d2a80 --- /dev/null +++ b/test/Dir/PyPackageDir/image/SConstruct @@ -0,0 +1,29 @@ +import sys, os + +oldsyspath = sys.path +dir_path = Dir('.').srcnode().abspath +dir_path = os.path.join(dir_path, 'syspath') +sys.path.append(dir_path) + +def TestPyPackageDir(env, modname): + packagepath = env.PyPackageDir(modname).abspath + # Convert from an absolute path back to a relative one for testing + commonprefix = os.path.commonprefix([dir_path, packagepath]) + relpath = os.path.relpath(packagepath, commonprefix) + relpath = relpath.replace(os.sep, '/') + print(relpath) + +print("Test identification of directory for a given python package") +env = Environment() +TestPyPackageDir(env, 'testmod1') +TestPyPackageDir(env, 'testmod2') +TestPyPackageDir(env, 'submod1.testmod3') +TestPyPackageDir(env, 'submod1.submod2.testmod4') + +print("Test parameter substitution") +env = Environment(FOO = 'submod1.submod2.testmod4') +TestPyPackageDir(env, '${FOO}') +env = Environment(FOO = 'submod1.submod2', BAR = 'testmod4') +TestPyPackageDir(env, '${FOO}.${BAR}') + +sys.path = oldsyspath diff --git a/test/Dir/PyPackageDir/image/sconstest.skip b/test/Dir/PyPackageDir/image/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/sconstest.skip b/test/Dir/PyPackageDir/image/syspath/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/__init__.py b/test/Dir/PyPackageDir/image/syspath/submod1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/sconstest.skip b/test/Dir/PyPackageDir/image/syspath/submod1/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/submod2/__init__.py b/test/Dir/PyPackageDir/image/syspath/submod1/submod2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/submod2/sconstest.skip b/test/Dir/PyPackageDir/image/syspath/submod1/submod2/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/submod2/testmod4.py b/test/Dir/PyPackageDir/image/syspath/submod1/submod2/testmod4.py new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/submod1/testmod3.py b/test/Dir/PyPackageDir/image/syspath/submod1/testmod3.py new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/testmod1/__init__.py b/test/Dir/PyPackageDir/image/syspath/testmod1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/testmod1/sconstest.skip b/test/Dir/PyPackageDir/image/syspath/testmod1/sconstest.skip new file mode 100644 index 0000000..e69de29 diff --git a/test/Dir/PyPackageDir/image/syspath/testmod2.py b/test/Dir/PyPackageDir/image/syspath/testmod2.py new file mode 100644 index 0000000..e69de29 diff --git a/test/toolpath/nested/image/SConstruct b/test/toolpath/nested/image/SConstruct index 211a0d7..78ae21d 100644 --- a/test/toolpath/nested/image/SConstruct +++ b/test/toolpath/nested/image/SConstruct @@ -55,4 +55,11 @@ print("env3['Toolpath_TestTool1_2'] =", env3.get('Toolpath_TestTool1_2')) print("env3['Toolpath_TestTool2_1'] =", env3.get('Toolpath_TestTool2_1')) print("env3['Toolpath_TestTool2_2'] =", env3.get('Toolpath_TestTool2_2')) + +print('Test using PyPackageDir') +toollist = ['Toolpath_TestTool2_1', 'Toolpath_TestTool2_2'] +env4 = Environment(tools = toollist, toolpath = [PyPackageDir('tools_example.subdir1.subdir2')]) +print("env4['Toolpath_TestTool2_1'] =", env4.get('Toolpath_TestTool2_1')) +print("env4['Toolpath_TestTool2_2'] =", env4.get('Toolpath_TestTool2_2')) + sys.path = oldsyspath diff --git a/test/toolpath/nested/nested.py b/test/toolpath/nested/nested.py index a736d58..df2ba07 100644 --- a/test/toolpath/nested/nested.py +++ b/test/toolpath/nested/nested.py @@ -57,6 +57,9 @@ env3['Toolpath_TestTool1_1'] = 1 env3['Toolpath_TestTool1_2'] = 1 env3['Toolpath_TestTool2_1'] = 1 env3['Toolpath_TestTool2_2'] = 1 +Test using PyPackageDir +env4['Toolpath_TestTool2_1'] = 1 +env4['Toolpath_TestTool2_2'] = 1 scons: done reading SConscript files. scons: Building targets ... scons: `.' is up to date. -- cgit v0.12 From 89091bfadcb56defc897acfa9753470e1eead6a2 Mon Sep 17 00:00:00 2001 From: grbd Date: Thu, 3 Aug 2017 12:33:51 -0700 Subject: Added docs for use of the PyPackageDir function --- doc/generated/functions.gen | 25 +++++++++++++++++++++++++ doc/generated/functions.mod | 4 ++++ doc/generated/tools.gen | 16 ++++++++++++++++ doc/generated/tools.mod | 4 ++++ doc/generated/variables.gen | 29 +++++++++++++++++++++++++++-- doc/generated/variables.mod | 2 ++ doc/scons.mod | 1 + doc/user/environments.xml | 32 ++++++++++++++++++++++++++++++++ src/CHANGES.txt | 1 + src/engine/SCons/Environment.xml | 23 +++++++++++++++++++++++ 10 files changed, 135 insertions(+), 2 deletions(-) diff --git a/doc/generated/functions.gen b/doc/generated/functions.gen index 8181d56..e72740a 100644 --- a/doc/generated/functions.gen +++ b/doc/generated/functions.gen @@ -3320,6 +3320,31 @@ Multiple targets can be passed in to a single call to + + + PyPackageDir(modulename) + + + env.PyPackageDir(modulename) + + + +This returns a Directory Node similar to Dir. +The python module / package is looked up and if located +the directory is returned for the location. +modulename +Is a named python package / module to +lookup the directory for it's location. + + +If +modulename +is a list, SCons returns a list of Dir nodes. +Construction variables are expanded in +modulename. + + + env.Replace(key=val, [...]) diff --git a/doc/generated/functions.mod b/doc/generated/functions.mod index 6183293..e460aaf 100644 --- a/doc/generated/functions.mod +++ b/doc/generated/functions.mod @@ -69,6 +69,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. PrependUnique"> Progress"> Pseudo"> +PyPackageDir"> Replace"> Repository"> Requires"> @@ -152,6 +153,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. env.PrependUnique"> env.Progress"> env.Pseudo"> +env.PyPackageDir"> env.Replace"> env.Repository"> env.Requires"> @@ -245,6 +247,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. PrependUnique"> Progress"> Pseudo"> +PyPackageDir"> Replace"> Repository"> Requires"> @@ -328,6 +331,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. env.PrependUnique"> env.Progress"> env.Pseudo"> +env.PyPackageDir"> env.Replace"> env.Repository"> env.Requires"> diff --git a/doc/generated/tools.gen b/doc/generated/tools.gen index d4b346d..0de9e03 100644 --- a/doc/generated/tools.gen +++ b/doc/generated/tools.gen @@ -95,6 +95,22 @@ Sets construction variables for generic POSIX C copmilers. Sets: &cv-link-CC;, &cv-link-CCCOM;, &cv-link-CCFLAGS;, &cv-link-CFILESUFFIX;, &cv-link-CFLAGS;, &cv-link-CPPDEFPREFIX;, &cv-link-CPPDEFSUFFIX;, &cv-link-FRAMEWORKPATH;, &cv-link-FRAMEWORKS;, &cv-link-INCPREFIX;, &cv-link-INCSUFFIX;, &cv-link-SHCC;, &cv-link-SHCCCOM;, &cv-link-SHCCFLAGS;, &cv-link-SHCFLAGS;, &cv-link-SHOBJSUFFIX;.Uses: &cv-link-PLATFORM;. + + clang + + +Set construction variables for the Clang C compiler. + +Sets: &cv-link-CC;, &cv-link-CCVERSION;, &cv-link-SHCCFLAGS;. + + + clangxx + + +Set construction variables for the Clang C++ compiler. + +Sets: &cv-link-CXX;, &cv-link-CXXVERSION;, &cv-link-SHCXXFLAGS;, &cv-link-SHOBJSUFFIX;, &cv-link-STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME;. + cvf diff --git a/doc/generated/tools.mod b/doc/generated/tools.mod index ee387ad..f9bc1d7 100644 --- a/doc/generated/tools.mod +++ b/doc/generated/tools.mod @@ -18,6 +18,8 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. as"> bcc32"> cc"> +clang"> +clangxx"> cvf"> cXX"> cyglink"> @@ -124,6 +126,8 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. as"> bcc32"> cc"> +clang"> +clangxx"> cvf"> cXX"> cyglink"> diff --git a/doc/generated/variables.gen b/doc/generated/variables.gen index e31fde1..0ad4c96 100644 --- a/doc/generated/variables.gen +++ b/doc/generated/variables.gen @@ -3046,7 +3046,7 @@ The command line used to call the Java archive tool. The string displayed when the Java archive tool is called -If this is not set, then $JARCOM (the command line) is displayed. +If this is not set, then $JARCOM (the command line) is displayed. @@ -3056,7 +3056,7 @@ env = Environment(JARCOMSTR = "JARchiving $SOURCES into $TARGET") The string displayed when the Java archive tool is called -If this is not set, then $JARCOM (the command line) is displayed. +If this is not set, then $JARCOM (the command line) is displayed. @@ -4179,6 +4179,29 @@ window and importing the shell's environment variables. + + MSVC_UWP_APP + + +Build libraries for a Universal Windows Platform (UWP) Application. + + + +If $MSVC_UWP_APP is set, the Visual Studio environment will be set up to point +to the Windows Store compatible libraries and Visual Studio runtimes. In doing so, +any libraries that are built will be able to be used in a UWP App and published +to the Windows Store. +This flag will only have an effect with Visual Studio 2015+. +This variable must be passed as an argument to the Environment() +constructor; setting it later has no effect. + + + +Valid values are '1' or '0' + + + + MSVC_VERSION @@ -4196,6 +4219,8 @@ constructor; setting it later has no effect. Valid values for Windows are +14.0, +14.0Exp, 12.0, 12.0Exp, 11.0, diff --git a/doc/generated/variables.mod b/doc/generated/variables.mod index 9d834de..8710f95 100644 --- a/doc/generated/variables.mod +++ b/doc/generated/variables.mod @@ -304,6 +304,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. $MSSDK_VERSION"> $MSVC_BATCH"> $MSVC_USE_SCRIPT"> +$MSVC_UWP_APP"> $MSVC_VERSION"> $MSVS"> $MSVS_ARCH"> @@ -927,6 +928,7 @@ THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT. $MSSDK_VERSION"> $MSVC_BATCH"> $MSVC_USE_SCRIPT"> +$MSVC_UWP_APP"> $MSVC_VERSION"> $MSVS"> $MSVS_ARCH"> diff --git a/doc/scons.mod b/doc/scons.mod index 8d64054..448a212 100644 --- a/doc/scons.mod +++ b/doc/scons.mod @@ -243,6 +243,7 @@ PrependENVPath"> PrependUnique"> Progress"> +PyPackageDir"> Replace"> Repository"> Requires"> diff --git a/doc/user/environments.xml b/doc/user/environments.xml index d591dff..4657c05 100644 --- a/doc/user/environments.xml +++ b/doc/user/environments.xml @@ -1887,6 +1887,38 @@ C:\Python35\Lib\site-packages\someinstalledpackage\SomeTool\__init__.py +
+ Using the &PyPackageDir; function to add to the toolpath + + + In some cases you may want to use a tool + located within a installed external pip package. + This is possible by the use of sys.path within the toolpath. + However in that situaion you need to provide a prefix to the toolname + to indicate where it is located within sys.path + + + +# namespaced target using sys.path +env = Environment(tools = ['tools_example.subdir1.subdir2.SomeTool'], toolpath = sys.path) +env.SomeTool(targets, sources) + + + + To avoid the use of a prefix within the name of the tool, + we can use the PyPackageDir(modulename) function to locate the directory of the python package. + PyPackageDir returns a Dir object which represents the path of the directory + for the python package / module specified as a parameter. + + + +# namespaced target using sys.path +env = Environment(tools = ['SomeTool'], toolpath = [PyPackageDir('tools_example.subdir1.subdir2')]) +env.SomeTool(targets, sources) + + +
+ diff --git a/src/CHANGES.txt b/src/CHANGES.txt index d032949..e875a01 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,7 @@ may cause rebuilds. In no case should rebuilds not happen. - Added a small fix to the python3 tool loader when loading a tool as a package - Added additional documentation to the user manual on using toolpaths with the environment This includes the use of sys.path to search for tools installed via pip or package managers + - Added support for a PyPackageDir function for use with the toolpath From William Blevins: - Updated D language scanner support to latest: 2.071.1. (PR #1924) diff --git a/src/engine/SCons/Environment.xml b/src/engine/SCons/Environment.xml index 92bc21a..ccee68d 100644 --- a/src/engine/SCons/Environment.xml +++ b/src/engine/SCons/Environment.xml @@ -2504,6 +2504,29 @@ env.PrependUnique(CCFLAGS = '-g', FOO = ['foo.yyy']) + + +(modulename) + + + +This returns a Directory Node similar to Dir. +The python module / package is looked up and if located +the directory is returned for the location. +modulename +Is a named python package / module to +lookup the directory for it's location. + + +If +modulename +is a list, SCons returns a list of Dir nodes. +Construction variables are expanded in +modulename. + + + + (key=val, [...]) -- cgit v0.12 From 334b9d54cf6810f55ffb14c2c42a03ac1f2ab433 Mon Sep 17 00:00:00 2001 From: grbd Date: Fri, 4 Aug 2017 02:57:11 -0700 Subject: Added fixes for docs / nested test for use of sys.path in toolpath --- doc/user/environments.xml | 49 ++++++++++++++++++++++------------- test/toolpath/nested/image/SConstruct | 6 ++++- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/doc/user/environments.xml b/doc/user/environments.xml index 4657c05..ae670a8 100644 --- a/doc/user/environments.xml +++ b/doc/user/environments.xml @@ -1781,7 +1781,7 @@ env.AppendENVPath('LIB', '/usr/local/lib')
-# Inbuilt tool or tool located within site_tools +# Builtin tool or tool located within site_tools env = Environment(tools = ['SomeTool']) env.SomeTool(targets, sources) @@ -1847,11 +1847,12 @@ SCons/Tool/SubDir1/SubDir2/SomeTool/__init__.py - It's important to note when creating tools within sub-directories, - there needs to be a __init__.py file within each directory. - This file can just be empty. - This is the same constraint used by python when loading modules - from within sub-directories (packages). + For python2 It's important to note when creating tools within sub-directories, + there needs to be a __init__.py file within each directory. + This file can just be empty. + This is the same constraint used by python when loading modules + from within sub-directories (packages). + For python3 this appears to be no longer a requirement. @@ -1859,20 +1860,30 @@ SCons/Tool/SubDir1/SubDir2/SomeTool/__init__.py Using sys.path within the toolpath - Using the toolpath option with sys.path - we can also include tools installed via the pip package manager. - + If we want to access tools externally to scons on the sys.path + (one example would be tools installed via the pip package manager) + One way to do this is to use sys.path with the toolpath. + + One thing to watch out for with this approach is that sys.path + can sometimes contains paths to .egg files instead of directories. + So we need to filter those out with this approach. + # namespaced target using sys.path within toolpath -env = Environment(tools = ['someinstalledpackage.SomeTool'], toolpath = sys.path) + +searchpaths = [] +for item in sys.path: + if os.path.isdir(item): searchpaths.append(item) + +env = Environment(tools = ['someinstalledpackage.SomeTool'], toolpath = searchpaths) env.SomeTool(targets, sources) - By supplying sys.path to the toolpath argument - and by using the nested syntax we can have scons search - the sys.path (which will include packages installed via pip). + By using sys.path with the toolpath argument + and by using the nested syntax we can have scons search + packages installed via pip for Tools. @@ -1893,19 +1904,21 @@ C:\Python35\Lib\site-packages\someinstalledpackage\SomeTool\__init__.py In some cases you may want to use a tool located within a installed external pip package. - This is possible by the use of sys.path within the toolpath. - However in that situaion you need to provide a prefix to the toolname + This is possible by the use of sys.path with the toolpath. + However in that situation you need to provide a prefix to the toolname to indicate where it is located within sys.path -# namespaced target using sys.path -env = Environment(tools = ['tools_example.subdir1.subdir2.SomeTool'], toolpath = sys.path) +searchpaths = [] +for item in sys.path: + if os.path.isdir(item): searchpaths.append(item) +env = Environment(tools = ['tools_example.subdir1.subdir2.SomeTool'], toolpath = searchpaths) env.SomeTool(targets, sources) - To avoid the use of a prefix within the name of the tool, + To avoid the use of a prefix within the name of the tool or filtering sys.path for directories, we can use the PyPackageDir(modulename) function to locate the directory of the python package. PyPackageDir returns a Dir object which represents the path of the directory for the python package / module specified as a parameter. diff --git a/test/toolpath/nested/image/SConstruct b/test/toolpath/nested/image/SConstruct index 78ae21d..a7c6ceb 100644 --- a/test/toolpath/nested/image/SConstruct +++ b/test/toolpath/nested/image/SConstruct @@ -39,6 +39,10 @@ dir_path = Dir('.').srcnode().abspath dir_path = os.path.join(dir_path, 'Libs') sys.path.append(dir_path) +searchpaths = [] +for item in sys.path: + if os.path.isdir(item): searchpaths.append(item) + toollist = ['tools_example.Toolpath_TestTool1', 'tools_example.Toolpath_TestTool2', 'tools_example.subdir1.Toolpath_TestTool1_1', @@ -47,7 +51,7 @@ toollist = ['tools_example.Toolpath_TestTool1', 'tools_example.subdir1.subdir2.Toolpath_TestTool2_2', ] -env3 = Environment(tools=toollist, toolpath=sys.path) +env3 = Environment(tools=toollist, toolpath=searchpaths) print("env3['Toolpath_TestTool1'] =", env3.get('Toolpath_TestTool1')) print("env3['Toolpath_TestTool2'] =", env3.get('Toolpath_TestTool2')) print("env3['Toolpath_TestTool1_1'] =", env3.get('Toolpath_TestTool1_1')) -- cgit v0.12