diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-08-07 22:15:47 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2017-08-07 22:15:47 (GMT) |
commit | 4936d53c1f92e522f147e846ea0860421098ffea (patch) | |
tree | 3e06e4cf41242a6650a43ba2a192721185ed25dc /src | |
parent | fbe80d5c70f497ed6aa4ae662cc1ace55d2cb8c1 (diff) | |
parent | 28e98c747043463bd777161ce98ec1e10ee8e921 (diff) | |
download | SCons-4936d53c1f92e522f147e846ea0860421098ffea.zip SCons-4936d53c1f92e522f147e846ea0860421098ffea.tar.gz SCons-4936d53c1f92e522f147e846ea0860421098ffea.tar.bz2 |
merge from upstream
Diffstat (limited to 'src')
-rw-r--r-- | src/CHANGES.txt | 1 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 9 | ||||
-rw-r--r-- | src/engine/SCons/Environment.xml | 23 | ||||
-rw-r--r-- | src/engine/SCons/Node/FS.py | 29 | ||||
-rw-r--r-- | src/engine/SCons/Script/__init__.py | 1 |
5 files changed, 63 insertions, 0 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index b8c985e..ab6797a 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -93,6 +93,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 Russel Winder: - Reordered the default D tools from "dmd, gdc, ldc" to "dmd, ldc, gdc". 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/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']) </summary> </scons_function> +<scons_function name="PyPackageDir"> +<arguments> +(modulename) +</arguments> +<summary> +<para> +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. +<varname>modulename</varname> +Is a named python package / module to +lookup the directory for it's location. +</para> +<para> +If +<varname>modulename</varname> +is a list, SCons returns a list of Dir nodes. +Construction variables are expanded in +<varname>modulename</varname>. +</para> +</summary> +</scons_function> + <scons_function name="Replace"> <arguments signature="env"> (key=val, [...]) 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', |