diff options
author | grbd <garlicbready@googlemail.com> | 2017-08-03 14:53:20 (GMT) |
---|---|---|
committer | grbd <garlicbready@googlemail.com> | 2017-08-03 14:53:20 (GMT) |
commit | 1849ff611b22a55b8933dc9f05db66114e34cd14 (patch) | |
tree | d149ae7ee604fbb9200b06ca96ebe49bfdb5e0f3 /src/engine/SCons/Node | |
parent | e2f981db1c087c2d684cfd4ace988a4e173d975d (diff) | |
download | SCons-1849ff611b22a55b8933dc9f05db66114e34cd14.zip SCons-1849ff611b22a55b8933dc9f05db66114e34cd14.tar.gz SCons-1849ff611b22a55b8933dc9f05db66114e34cd14.tar.bz2 |
Added support for a PyPackageDir function
Diffstat (limited to 'src/engine/SCons/Node')
-rw-r--r-- | src/engine/SCons/Node/FS.py | 29 |
1 files changed, 29 insertions, 0 deletions
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 |