Skip to content

Commit cddab69

Browse files
committed
Use external python for configuration variables.
SCons might be run by a different python than for which we install. Run env['python'] to determine NumPy paths and distutils build names.
1 parent 075dbe9 commit cddab69

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

SConstruct

+10-6
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ def getsyspaths(*names):
3131
s = os.pathsep.join(filter(None, map(os.environ.get, names)))
3232
return filter(os.path.exists, s.split(os.pathsep))
3333

34-
def pyconfigvar(name):
35-
cmd = [env['python'], '-c', '\n'.join((
36-
'from distutils.sysconfig import get_config_var',
37-
'print get_config_var(%r)' % name))]
38-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
34+
def pyoutput(cmd):
35+
proc = subprocess.Popen([env['python'], '-c', cmd],
36+
stdout=subprocess.PIPE)
3937
out = proc.communicate()[0]
4038
return out.rstrip()
4139

40+
def pyconfigvar(name):
41+
cmd = '\n'.join((
42+
'from distutils.sysconfig import get_config_var',
43+
'print get_config_var(%r)' % name))
44+
return pyoutput(cmd)
45+
4246
# copy system environment variables related to compilation
4347
DefaultEnvironment(ENV=subdictionary(os.environ, '''
4448
PATH PYTHONPATH
@@ -126,7 +130,7 @@ if env['profile']:
126130

127131
builddir = env.Dir('build/%s-%s' % (env['build'], platform.machine()))
128132

129-
Export('env', 'pyconfigvar')
133+
Export('env', 'pyconfigvar', 'pyoutput')
130134

131135
if os.path.isfile('sconscript.local'):
132136
env.SConscript('sconscript.local')

extensions/SConscript

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import sys
22
import os
3-
from distutils.core import Distribution
4-
from distutils.command.build import build
53

6-
Import('env')
4+
Import('env', 'pyoutput')
75

86
# make sure numpy headers are available
9-
from numpy.distutils.misc_util import get_numpy_include_dirs
10-
env.AppendUnique(CPPPATH=get_numpy_include_dirs())
7+
npdirs = pyoutput(
8+
'from numpy.distutils.misc_util import get_numpy_include_dirs\n'
9+
'print "\\n".join(get_numpy_include_dirs())')
10+
npdirs = map(str.strip, npdirs.split('\n'))
11+
env.AppendUnique(CPPPATH=npdirs)
1112

1213
# configure the boost_python library, which may have different extensions
1314
if not (GetOption('clean') or env.GetOption('help')):
@@ -28,9 +29,14 @@ test = env.Alias('test', develop,
2829
AlwaysBuild(test)
2930

3031
# normal install - trick distutils into using this module.
31-
bcmd = build(Distribution())
32-
bcmd.finalize_options()
33-
distmodfile = os.path.join(bcmd.build_platlib,
32+
build_platlib = pyoutput('\n'.join([
33+
"from distutils.core import Distribution",
34+
"from distutils.command.build import build",
35+
"bcmd = build(Distribution())",
36+
"bcmd.finalize_options()",
37+
"print bcmd.build_platlib",
38+
]))
39+
distmodfile = os.path.join(build_platlib,
3440
'pyobjcryst', os.path.basename(str(module[0])))
3541
cmd_install = '$python setup.py install'
3642
if 'prefix' in env:

0 commit comments

Comments
 (0)