return result
if os.name == 'java':
-
python_executable = os.path.join(sys.prefix, 'jython')
-
else:
-
python_executable = sys.executable
if sys.platform == 'win32':
# see also sys.prefix documentation
return python_minor_version_string()
- def get_platform_python(self):
+ def get_platform_python_info(self):
"""
Returns a path to a Python executable suitable for testing on
- this platform.
-
- Mac OS X has no static libpython for SWIG to link against,
- so we have to link against Apple's framwork version. However,
- testing must use the executable version that corresponds to the
- framework we link against, or else we get interpreter errors.
- """
- if sys.platform[:6] == 'darwin':
- return sys.prefix + '/bin/python'
- else:
- global python
- return python
-
- def get_quoted_platform_python(self):
- """
- Returns a quoted path to a Python executable suitable for testing on
- this platform.
-
- Mac OS X has no static libpython for SWIG to link against,
- so we have to link against Apple's framwork version. However,
- testing must use the executable version that corresponds to the
- framework we link against, or else we get interpreter errors.
- """
- if sys.platform[:6] == 'darwin':
- return '"' + self.get_platform_python() + '"'
- else:
- global _python_
- return _python_
-
-# def get_platform_sys_prefix(self):
-# """
-# Returns a "sys.prefix" value suitable for linking on this platform.
-#
-# Mac OS X has a built-in Python but no static libpython,
-# so we must link to it using Apple's 'framework' scheme.
-# """
-# if sys.platform[:6] == 'darwin':
-# fmt = '/System/Library/Frameworks/Python.framework/Versions/%s/'
-# return fmt % self.get_python_version()
-# else:
-# return sys.prefix
-
- def get_python_frameworks_flags(self):
- """
- Returns a FRAMEWORKS value for linking with Python.
-
- Mac OS X has a built-in Python but no static libpython,
- so we must link to it using Apple's 'framework' scheme.
- """
- if sys.platform[:6] == 'darwin':
- return 'Python'
- else:
- return ''
-
- def get_python_inc(self):
+ this platform and its associated include path, library path,
+ and library name.
"""
- Returns a path to the Python include directory.
+ python = self.where_is('python')
+ if not python:
+ self.skip_test('Can not find installed "python", skipping test.\n')
- Mac OS X has a built-in Python but no static libpython,
- so we must link to it using Apple's 'framework' scheme.
- """
- if sys.platform[:6] == 'darwin':
- return sys.prefix + '/Headers'
- try:
- import distutils.sysconfig
- except ImportError:
- return os.path.join(sys.prefix, 'include',
- 'python' + self.get_python_version())
- else:
- return distutils.sysconfig.get_python_inc()
+ self.run(program = python, stdin = """\
+import os, sys
+try:
+ py_ver = 'python%d.%d' % sys.version_info[:2]
+except AttributeError:
+ py_ver = 'python' + sys.version[:3]
+print os.path.join(sys.prefix, 'include', py_ver)
+print os.path.join(sys.prefix, 'lib', py_ver, 'config')
+print py_ver
+""")
- def get_python_library_path(self):
- """
- Returns the full path of the Python static library (libpython*.a)
- """
- if sys.platform[:6] == 'darwin':
- # Use the framework version (or try to) since that matches
- # the executable and headers we return elsewhere.
- python_lib = os.path.join(sys.prefix, 'Python')
- if os.path.exists(python_lib):
- return python_lib
- python_version = self.get_python_version()
- python_lib = os.path.join(sys.prefix, 'lib',
- 'python%s' % python_version, 'config',
- 'libpython%s.a' % python_version)
- if os.path.exists(python_lib):
- return python_lib
- # We can't find it, so maybe it's in the standard path
- return ''
+ return [python] + string.split(string.strip(self.stdout()), '\n')
def wait_for(self, fname, timeout=10.0, popen=None):
"""
test = TestSCons.TestSCons()
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+ test,skip_test('Can not find installed "python", skipping test.\n')
test.write('myswig.py', r"""
""")
test.write('SConstruct', """
-env = Environment(tools=['default', 'swig'], SWIG = r'%(_python_)s myswig.py')
+env = Environment(tools=['default', 'swig'],
+ SWIG = [r'%(python)s', 'myswig.py'])
env.Program(target = 'test1', source = 'test1.i')
env.CFile(target = 'test2', source = 'test2.i')
env.Clone(SWIGFLAGS = '-c++').Program(target = 'test3', source = 'test3.i')
test = TestSCons.TestSCons()
-test = TestSCons.TestSCons()
-
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
test.write(['SConstruct'], """\
env = Environment(SWIGFLAGS = '-python -c++',
- CPPPATH=r"%(python_include_dir)s",
- SWIG=r'%(swig)s',
+ CPPPATH=[r"%(python_include)s"],
+ SWIG=[r'%(swig)s'],
SWIGOUTDIR='python/build dir',
- FRAMEWORKS='%(python_frameworks_flags)s',
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
)
import sys
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+ test,skip_test('Can not find installed "python", skipping test.\n')
test.subdir('inc1', 'inc2')
foo = Environment(SWIGFLAGS='-python',
SWIGPATH=['inc1', 'inc2'])
swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
foo.CFile(target = 'dependent', source = ['dependent.i'])
""" % locals())
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
test.subdir(['source'])
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
-python_frameworks_flags = test.get_python_frameworks_flags()
-
test.write(['SConstruct'], """\
#
# Create the build environment.
#
-env = Environment(CPPPATH = [".", r'%(python_include_dir)s'],
+env = Environment(CPPPATH = [".", r'%(python_include)s'],
CPPDEFINES = "NDEBUG",
- SWIG =r'%(swig)s',
+ SWIG = [r'%(swig)s'],
SWIGFLAGS = ["-python", "-c++"],
SWIGCXXFILESUFFIX = "_wrap.cpp",
LDMODULEPREFIX='_',
LDMODULESUFFIX='%(_dll)s',
- FRAMEWORKS='%(python_frameworks_flags)s')
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
+ )
import sys
if sys.version[0] == '1':
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-_python_ = test.get_quoted_platform_python()
-
+python = test.where_is('python')
+if not python:
+ test.skip_test('Can not find installed "python", skipping test.\n')
test.write("dependency.i", """\
test.write('SConstruct', """
foo = Environment(SWIGFLAGS='-python')
swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', r'wrapper.py', swig])
foo.CFile(target = 'dependent', source = ['dependent.i'])
""" % locals())
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-
-python = test.where_is('python')
-
-# handle testing on other platforms:
-ldmodule_prefix = '_'
-
-test.run(program = python, stdin = """\
-import os, sys
-try:
- py_ver = 'python%d.%d' % sys.version_info[:2]
-except AttributeError:
- py_ver = 'python' + sys.version[:3]
-print os.path.join(sys.prefix, 'include', py_ver)
-print os.path.join(sys.prefix, 'lib', py_ver, 'config')
-print py_ver
-""")
-
-#TODO(1.5) config_info = test.stdout().strip().split('\n')
-config_info = string.split(string.strip(test.stdout()), '\n')
-python_include,python_libpath,python_lib = config_info
-
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
+# handle testing on other platforms:
+ldmodule_prefix = '_'
+
test.write("wrapper.py",
"""import os
import string
test.write('SConstruct', """\
foo = Environment(SWIGFLAGS='-python',
- CPPPATH=r'%(python_include)s',
+ CPPPATH=[r'%(python_include)s'],
LDMODULEPREFIX='%(ldmodule_prefix)s',
LDMODULESUFFIX='%(_dll)s',
- SWIG=r'%(swig)s',
- LIBPATH=r'%(python_libpath)s',
+ SWIG=[r'%(swig)s'],
+ LIBPATH=[r'%(python_libpath)s'],
LIBS='%(python_lib)s',
)
foo.Append(SWIGFLAGS = ' -classic')
swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'"%(python)s" wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
foo.LoadableModule(target = 'foo', source = ['foo.c', 'foo.i'])
bar.LoadableModule(target = 'bar', source = ['bar.c', 'bar.i'])
""" % locals())
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
test.write(['SConstruct'], """\
env = Environment(SWIGFLAGS = '-python -c++',
- CPPPATH=r"%(python_include_dir)s",
- SWIG=r'%(swig)s',
- FRAMEWORKS='%(python_frameworks_flags)s',
- )
+ CPPPATH=[r'%(python_include)s'],
+ SWIG=[r'%(swig)s'],
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
+ )
import sys
if sys.version[0] == '1':
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
test.write(['SConstruct'], """\
env = Environment(SWIGFLAGS = '-python -c++',
- CPPPATH=r"%(python_include_dir)s",
- SWIG=r'%(swig)s',
- FRAMEWORKS='%(python_frameworks_flags)s',
+ CPPPATH=[r'%(python_include)s'],
+ SWIG=[r'%(swig)s'],
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
)
import sys
be created.
"""
+import os
import sys
import TestSCons
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-_python_ = test.get_quoted_platform_python()
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
+if not os.path.exists(Python_h):
+ test.skip_test('Can not find %s, skipping test.\n' % Python_h)
# handle testing on other platforms:
ldmodule_prefix = '_'
-python_include_dir = test.get_python_inc()
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
test.write("dependency.i", """\
%module dependency
""")
test.write('SConstruct', """
foo = Environment(SWIGFLAGS=['-python', '-noproxy'],
- CPPPATH='%(python_include_dir)s',
+ CPPPATH=[r'%(python_include)s'],
LDMODULEPREFIX='%(ldmodule_prefix)s',
LDMODULESUFFIX='%(_dll)s',
- FRAMEWORKS='%(python_frameworks_flags)s',
+ SWIG=[r'%(swig)s'],
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
)
swig = foo.Dictionary('SWIG')
-bar = foo.Clone(SWIG = r'%(_python_)s wrapper.py ' + swig)
+bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig])
foo.CFile(target = 'dependent', source = ['dependent.i'])
""" % locals())
if sys.platform == 'win32':
_dll = '.dll'
else:
- _dll = '.so'
+ _dll = '.so'
test = TestSCons.TestSCons()
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
+if not os.path.exists(Python_h):
+ test.skip_test('Can not find %s, skipping test.\n' % Python_h)
# handle testing on other platforms:
ldmodule_prefix = '_'
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
-if not os.path.exists(Python_h):
- test.skip_test('Can not find %s, skipping test.\n' % Python_h)
-
-python_frameworks_flags = test.get_python_frameworks_flags()
-
test.write("module.i", """\
%module modulename
test.write('SConstruct', """
foo = Environment(SWIGFLAGS='-python',
- CPPPATH='%(python_include_dir)s',
+ CPPPATH=['%(python_include)s'],
LDMODULEPREFIX='%(ldmodule_prefix)s',
LDMODULESUFFIX='%(_dll)s',
- FRAMEWORKS='%(python_frameworks_flags)s',
- SWIG=r'%(swig)s',
+ SWIG=[r'%(swig)s'],
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
)
import sys
test.subdir('sub')
swig = test.where_is('swig')
-
if not swig:
test.skip_test('Can not find installed "swig", skipping test.\n')
-python = test.get_platform_python()
-_python_ = test.get_quoted_platform_python()
-
-# handle testing on other platforms:
-ldmodule_prefix = '_'
-
-python_include_dir = test.get_python_inc()
-
-Python_h = os.path.join(python_include_dir, 'Python.h')
-
+python, python_include, python_libpath, python_lib = \
+ test.get_platform_python_info()
+Python_h = os.path.join(python_include, 'Python.h')
if not os.path.exists(Python_h):
test.skip_test('Can not find %s, skipping test.\n' % Python_h)
-python_frameworks_flags = test.get_python_frameworks_flags()
+# handle testing on other platforms:
+ldmodule_prefix = '_'
test.write('SConstruct', """
env = Environment(SWIGFLAGS='-python',
- CPPPATH='%(python_include_dir)s/',
+ CPPPATH=['%(python_include)s/'],
LDMODULEPREFIX='%(ldmodule_prefix)s',
LDMODULESUFFIX='%(_dll)s',
- FRAMEWORKS='%(python_frameworks_flags)s',
SWIG=r'%(swig)s',
+ LIBPATH=[r'%(python_libpath)s'],
+ LIBS='%(python_lib)s',
)
import sys