Skip to content

Commit

Permalink
Add python config
Browse files Browse the repository at this point in the history
  • Loading branch information
brianv0 committed Aug 5, 2019
1 parent 17aee87 commit 0bc8c03
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions configs/python.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- python -*-

import lsst.sconsUtils
import re
import os.path
import subprocess

dependencies = {}

class Configuration(lsst.sconsUtils.Configuration):

def __init__(self):
self.name, self.root = self.parseFilename(__file__)

@staticmethod
def _get_config_var(name):
"""The relevant Python is not guaranteed to be the Python
that we are using to run SCons so we must shell out to the
PATH python."""
pycmd = 'import distutils.sysconfig as s; print(s.get_config_var("{}"))'.format(name)
result = subprocess.check_output(["python", "-c", pycmd]).decode().strip()
# Be consistent with native interface
if result == "None":
result = None
return result

def configure(self, conf, packages, check=False, build=True):
lsst.sconsUtils.log.info("Configuring package '%s'." % self.name)
conf.env.AppendUnique(XCPPPATH=self._get_config_var("CONFINCLUDEPY").split())
libDir = self._get_config_var("LIBPL")
conf.env.AppendUnique(LIBPATH=[libDir])
pylibrary = self._get_config_var("LIBRARY")
mat = re.search("(python.*)\.(a|so|dylib)$", pylibrary)
if mat:
conf.env.libs["python"].append(mat.group(1))
lsst.sconsUtils.log.info("Adding '%s' to target 'python'." % mat.group(1))
for w in (" ".join([self._get_config_var("MODLIBS"),
self._get_config_var("SHLIBS")])).split():
mat = re.search(r"^-([Ll])(.*)", w)
if mat:
lL = mat.group(1)
arg = mat.group(2)
if lL == "l":
if not arg in conf.env.libs:
conf.env.libs["python"].append(arg)
lsst.sconsUtils.log.info("Adding '%s' to target 'python'." % arg)
else:
if os.path.isdir(arg):
conf.env.AppendUnique(LIBPATH=[arg])
lsst.sconsUtils.log.info("Adding '%s' to link path." % arg)
if conf.env['PLATFORM'] == 'darwin':
frameworkDir = libDir # search up the libDir tree for the proper home for frameworks
while frameworkDir and not re.match("^//*$", frameworkDir):
frameworkDir, d2 = os.path.split(frameworkDir)
if d2 == "Python.framework":
if not "Python" in os.listdir(os.path.join(frameworkDir, d2)):
lsst.sconUtils.log.warn(
"Expected to find Python in framework directory %s, but it isn't there"
% frameworkDir
)
return False
break
opt = "-F%s" % frameworkDir
if opt not in conf.env["LDMODULEFLAGS"]:
conf.env.Append(LDMODULEFLAGS = [opt,])
return True

config = Configuration()

0 comments on commit 0bc8c03

Please sign in to comment.