2011-09-10 11:13:51 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
2014-07-25 18:15:23 +02:00
|
|
|
# Thomas Nagy, 2007-2014 (ita)
|
2011-09-10 11:13:51 +02:00
|
|
|
# Gustavo Carneiro (gjc), 2007
|
|
|
|
|
|
|
|
"""
|
|
|
|
Support for Python, detect the headers and libraries and provide
|
|
|
|
*use* variables to link C/C++ programs against them::
|
|
|
|
|
|
|
|
def options(opt):
|
|
|
|
opt.load('compiler_c python')
|
|
|
|
def configure(conf):
|
|
|
|
conf.load('compiler_c python')
|
|
|
|
conf.check_python_version((2,4,2))
|
|
|
|
conf.check_python_headers()
|
|
|
|
def build(bld):
|
|
|
|
bld.program(features='pyembed', source='a.c', target='myprog')
|
|
|
|
bld.shlib(features='pyext', source='b.c', target='mylib')
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os, sys
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
from waflib import Utils, Options, Errors, Logs, Task, Node
|
2011-09-10 11:13:51 +02:00
|
|
|
from waflib.TaskGen import extension, before_method, after_method, feature
|
|
|
|
from waflib.Configure import conf
|
|
|
|
|
|
|
|
FRAG = '''
|
|
|
|
#include <Python.h>
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void Py_Initialize(void);
|
|
|
|
void Py_Finalize(void);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-24 22:53:07 +02:00
|
|
|
int main(int argc, char **argv)
|
2011-09-10 11:13:51 +02:00
|
|
|
{
|
2012-11-04 10:29:36 +01:00
|
|
|
(void)argc; (void)argv;
|
2011-09-10 11:13:51 +02:00
|
|
|
Py_Initialize();
|
|
|
|
Py_Finalize();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
'''
|
|
|
|
"""
|
|
|
|
Piece of C/C++ code used in :py:func:`waflib.Tools.python.check_python_headers`
|
|
|
|
"""
|
|
|
|
|
|
|
|
INST = '''
|
|
|
|
import sys, py_compile
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
py_compile.compile(sys.argv[1], sys.argv[2], sys.argv[3], True)
|
2011-09-10 11:13:51 +02:00
|
|
|
'''
|
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
Piece of Python code used in :py:func:`waflib.Tools.python.pytask` for byte-compiling python files
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
|
|
|
|
2011-12-17 23:07:25 +01:00
|
|
|
DISTUTILS_IMP = ['from distutils.sysconfig import get_config_var, get_python_lib']
|
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
@before_method('process_source')
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
@feature('py')
|
|
|
|
def feature_py(self):
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
Create tasks to byte-compile .py files and install them, if requested
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
2014-07-25 18:15:23 +02:00
|
|
|
self.install_path = getattr(self, 'install_path', '${PYTHONDIR}')
|
|
|
|
install_from = getattr(self, 'install_from', None)
|
|
|
|
if install_from and not isinstance(install_from, Node.Node):
|
|
|
|
install_from = self.path.find_dir(install_from)
|
|
|
|
self.install_from = install_from
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
ver = self.env.PYTHON_VERSION
|
|
|
|
if not ver:
|
|
|
|
self.bld.fatal('Installing python files requires PYTHON_VERSION, try conf.check_python_version')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
if int(ver.replace('.', '')) > 31:
|
|
|
|
self.install_32 = True
|
2011-09-10 11:13:51 +02:00
|
|
|
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
@extension('.py')
|
|
|
|
def process_py(self, node):
|
|
|
|
"""
|
|
|
|
Add signature of .py file, so it will be byte-compiled when necessary
|
|
|
|
"""
|
2014-07-25 18:15:23 +02:00
|
|
|
assert(node.get_bld_sig())
|
|
|
|
assert(getattr(self, 'install_path')), 'add features="py"'
|
|
|
|
|
|
|
|
# where to install the python file
|
|
|
|
if self.install_path:
|
|
|
|
if self.install_from:
|
|
|
|
self.bld.install_files(self.install_path, [node], cwd=self.install_from, relative_trick=True)
|
|
|
|
else:
|
|
|
|
self.bld.install_files(self.install_path, [node])
|
|
|
|
|
|
|
|
lst = []
|
|
|
|
if self.env.PYC:
|
|
|
|
lst.append('pyc')
|
|
|
|
if self.env.PYO:
|
|
|
|
lst.append('pyo')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
if self.install_path:
|
|
|
|
if self.install_from:
|
|
|
|
pyd = Utils.subst_vars("%s/%s" % (self.install_path, node.path_from(self.install_from)), self.env)
|
|
|
|
else:
|
|
|
|
pyd = Utils.subst_vars("%s/%s" % (self.install_path, node.path_from(self.path)), self.env)
|
|
|
|
else:
|
|
|
|
pyd = node.abspath()
|
|
|
|
|
|
|
|
for ext in lst:
|
|
|
|
if self.env.PYTAG:
|
|
|
|
# __pycache__ installation for python 3.2 - PEP 3147
|
|
|
|
name = node.name[:-3]
|
|
|
|
pyobj = node.parent.get_bld().make_node('__pycache__').make_node("%s.%s.%s" % (name, self.env.PYTAG, ext))
|
|
|
|
pyobj.parent.mkdir()
|
|
|
|
else:
|
|
|
|
pyobj = node.change_ext(".%s" % ext)
|
|
|
|
|
|
|
|
tsk = self.create_task(ext, node, pyobj)
|
|
|
|
tsk.pyd = pyd
|
|
|
|
|
|
|
|
if self.install_path:
|
2014-08-29 20:05:58 +02:00
|
|
|
self.bld.install_files(self.install_path, pyobj, cwd=node.parent.get_bld(), relative_trick=True)
|
2014-07-25 18:15:23 +02:00
|
|
|
|
|
|
|
class pyc(Task.Task):
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
"""
|
|
|
|
Byte-compiling python files
|
|
|
|
"""
|
|
|
|
color = 'PINK'
|
|
|
|
def run(self):
|
|
|
|
cmd = [Utils.subst_vars('${PYTHON}', self.env), '-c', INST, self.inputs[0].abspath(), self.outputs[0].abspath(), self.pyd]
|
|
|
|
ret = self.generator.bld.exec_command(cmd)
|
|
|
|
return ret
|
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
class pyo(Task.Task):
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
Byte-compiling python files
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
color = 'PINK'
|
|
|
|
def run(self):
|
2014-07-25 18:15:23 +02:00
|
|
|
cmd = [Utils.subst_vars('${PYTHON}', self.env), Utils.subst_vars('${PYFLAGS_OPT}', self.env), '-c', INST, self.inputs[0].abspath(), self.outputs[0].abspath(), self.pyd]
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
ret = self.generator.bld.exec_command(cmd)
|
|
|
|
return ret
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
@feature('pyext')
|
|
|
|
@before_method('propagate_uselib_vars', 'apply_link')
|
|
|
|
@after_method('apply_bundle')
|
|
|
|
def init_pyext(self):
|
|
|
|
"""
|
|
|
|
Change the values of *cshlib_PATTERN* and *cxxshlib_PATTERN* to remove the
|
|
|
|
*lib* prefix from library names.
|
|
|
|
"""
|
|
|
|
self.uselib = self.to_list(getattr(self, 'uselib', []))
|
|
|
|
if not 'PYEXT' in self.uselib:
|
|
|
|
self.uselib.append('PYEXT')
|
|
|
|
# override shlib_PATTERN set by the osx module
|
2012-10-21 11:29:40 +02:00
|
|
|
self.env.cshlib_PATTERN = self.env.cxxshlib_PATTERN = self.env.macbundle_PATTERN = self.env.pyext_PATTERN
|
|
|
|
self.env.fcshlib_PATTERN = self.env.dshlib_PATTERN = self.env.pyext_PATTERN
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2012-03-18 19:05:54 +01:00
|
|
|
try:
|
|
|
|
if not self.install_path:
|
|
|
|
return
|
|
|
|
except AttributeError:
|
|
|
|
self.install_path = '${PYTHONARCHDIR}'
|
|
|
|
|
2011-09-10 11:13:51 +02:00
|
|
|
@feature('pyext')
|
|
|
|
@before_method('apply_link', 'apply_bundle')
|
|
|
|
def set_bundle(self):
|
2012-01-05 21:01:11 +01:00
|
|
|
if Utils.unversioned_sys_platform() == 'darwin':
|
2011-09-10 11:13:51 +02:00
|
|
|
self.mac_bundle = True
|
|
|
|
|
|
|
|
@before_method('propagate_uselib_vars')
|
|
|
|
@feature('pyembed')
|
|
|
|
def init_pyembed(self):
|
|
|
|
"""
|
|
|
|
Add the PYEMBED variable.
|
|
|
|
"""
|
|
|
|
self.uselib = self.to_list(getattr(self, 'uselib', []))
|
|
|
|
if not 'PYEMBED' in self.uselib:
|
|
|
|
self.uselib.append('PYEMBED')
|
|
|
|
|
|
|
|
@conf
|
2011-12-17 23:07:25 +01:00
|
|
|
def get_python_variables(self, variables, imports=None):
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
2011-12-17 23:07:25 +01:00
|
|
|
Spawn a new python process to dump configuration variables
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
:param variables: variables to print
|
|
|
|
:type variables: list of string
|
|
|
|
:param imports: one import by element
|
|
|
|
:type imports: list of string
|
|
|
|
:return: the variable values
|
|
|
|
:rtype: list of string
|
|
|
|
"""
|
2011-12-17 23:07:25 +01:00
|
|
|
if not imports:
|
|
|
|
try:
|
|
|
|
imports = self.python_imports
|
|
|
|
except AttributeError:
|
|
|
|
imports = DISTUTILS_IMP
|
|
|
|
|
|
|
|
program = list(imports) # copy
|
2011-09-10 11:13:51 +02:00
|
|
|
program.append('')
|
|
|
|
for v in variables:
|
|
|
|
program.append("print(repr(%s))" % v)
|
|
|
|
os_env = dict(os.environ)
|
|
|
|
try:
|
|
|
|
del os_env['MACOSX_DEPLOYMENT_TARGET'] # see comments in the OSX tool
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
try:
|
2011-12-17 23:07:25 +01:00
|
|
|
out = self.cmd_and_log(self.env.PYTHON + ['-c', '\n'.join(program)], env=os_env)
|
2011-09-10 11:13:51 +02:00
|
|
|
except Errors.WafError:
|
2011-12-17 23:07:25 +01:00
|
|
|
self.fatal('The distutils module is unusable: install "python-devel"?')
|
2012-06-16 02:43:02 +02:00
|
|
|
self.to_log(out)
|
2011-09-10 11:13:51 +02:00
|
|
|
return_values = []
|
|
|
|
for s in out.split('\n'):
|
|
|
|
s = s.strip()
|
|
|
|
if not s:
|
|
|
|
continue
|
|
|
|
if s == 'None':
|
|
|
|
return_values.append(None)
|
2012-06-19 18:02:04 +02:00
|
|
|
elif (s[0] == "'" and s[-1] == "'") or (s[0] == '"' and s[-1] == '"'):
|
|
|
|
return_values.append(eval(s))
|
2011-09-10 11:13:51 +02:00
|
|
|
elif s[0].isdigit():
|
|
|
|
return_values.append(int(s))
|
|
|
|
else: break
|
|
|
|
return return_values
|
|
|
|
|
|
|
|
@conf
|
|
|
|
def check_python_headers(conf):
|
|
|
|
"""
|
|
|
|
Check for headers and libraries necessary to extend or embed python by using the module *distutils*.
|
|
|
|
On success the environment variables xxx_PYEXT and xxx_PYEMBED are added:
|
|
|
|
|
|
|
|
* PYEXT: for compiling python extensions
|
|
|
|
* PYEMBED: for embedding a python interpreter
|
|
|
|
"""
|
|
|
|
|
|
|
|
# FIXME rewrite
|
|
|
|
|
2012-07-03 15:42:17 +02:00
|
|
|
env = conf.env
|
|
|
|
if not env['CC_NAME'] and not env['CXX_NAME']:
|
2011-09-10 11:13:51 +02:00
|
|
|
conf.fatal('load a compiler first (gcc, g++, ..)')
|
|
|
|
|
2012-07-03 15:42:17 +02:00
|
|
|
if not env['PYTHON_VERSION']:
|
2011-09-10 11:13:51 +02:00
|
|
|
conf.check_python_version()
|
|
|
|
|
|
|
|
pybin = conf.env.PYTHON
|
|
|
|
if not pybin:
|
2012-07-03 15:42:17 +02:00
|
|
|
conf.fatal('Could not find the python executable')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-02-04 11:55:26 +01:00
|
|
|
v = 'prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
|
2011-09-10 11:13:51 +02:00
|
|
|
try:
|
2011-12-17 23:07:25 +01:00
|
|
|
lst = conf.get_python_variables(["get_config_var('%s') or ''" % x for x in v])
|
2011-09-10 11:13:51 +02:00
|
|
|
except RuntimeError:
|
|
|
|
conf.fatal("Python development headers not found (-v for details).")
|
|
|
|
|
|
|
|
vals = ['%s = %r' % (x, y) for (x, y) in zip(v, lst)]
|
|
|
|
conf.to_log("Configuration returned from %r:\n%r\n" % (pybin, '\n'.join(vals)))
|
|
|
|
|
|
|
|
dct = dict(zip(v, lst))
|
|
|
|
x = 'MACOSX_DEPLOYMENT_TARGET'
|
|
|
|
if dct[x]:
|
|
|
|
conf.env[x] = conf.environ[x] = dct[x]
|
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
if not env.pyext_PATTERN:
|
|
|
|
if dct['SO']:
|
|
|
|
env.pyext_PATTERN = '%s' + dct['SO'] # not a mistake
|
|
|
|
else:
|
|
|
|
env.pyext_PATTERN = (conf.env.cshlib_PATTERN or conf.env.cxxshlib_PATTERN).lstrip('lib')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
# We require pythonX.Y-config to get the flags
|
|
|
|
num = '.'.join(env['PYTHON_VERSION'].split('.')[:2])
|
|
|
|
conf.find_program([''.join(pybin) + '-config', 'python%s-config' % num, 'python-config-%s' % num, 'python%sm-config' % num], var='PYTHON_CONFIG', msg="python-config")
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
flags = ['--cflags', '--libs', '--ldflags']
|
|
|
|
xx = conf.env.CXX_NAME and 'cxx' or 'c'
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
conf.check_cfg(msg='Asking python-config for pyembed %r flags' % ' '.join(flags),
|
|
|
|
path=conf.env.PYTHON_CONFIG, package='', uselib_store='PYEMBED', args=flags)
|
|
|
|
conf.check(header_name='Python.h', define_name='HAVE_PYEMBED', msg='Getting pyembed flags from python-config',
|
|
|
|
fragment=FRAG, errmsg='Could not build a python embedded interpreter',
|
|
|
|
features='%s %sprogram pyembed' % (xx, xx))
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
conf.check_cfg(msg='Asking python-config for pyext %r flags' % ' '.join(flags),
|
|
|
|
path=conf.env.PYTHON_CONFIG, package='', uselib_store='PYEXT', args=flags)
|
|
|
|
conf.check(header_name='Python.h', define_name='HAVE_PYEXT', msg='Getting pyext flags from python-config',
|
|
|
|
features='%s %sshlib pyext' % (xx, xx), fragment=FRAG, errmsg='Could not build python extensions')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2014-08-31 21:11:41 +02:00
|
|
|
conf.define('HAVE_PYTHON_H', 1)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
@conf
|
|
|
|
def check_python_version(conf, minver=None):
|
|
|
|
"""
|
|
|
|
Check if the python interpreter is found matching a given minimum version.
|
|
|
|
minver should be a tuple, eg. to check for python >= 2.4.2 pass (2,4,2) as minver.
|
|
|
|
|
|
|
|
If successful, PYTHON_VERSION is defined as 'MAJOR.MINOR'
|
|
|
|
(eg. '2.4') of the actual python version found, and PYTHONDIR is
|
|
|
|
defined, pointing to the site-packages directory appropriate for
|
|
|
|
this python version, where modules/packages/extensions should be
|
|
|
|
installed.
|
|
|
|
|
|
|
|
:param minver: minimum version
|
|
|
|
:type minver: tuple of int
|
|
|
|
"""
|
|
|
|
assert minver is None or isinstance(minver, tuple)
|
|
|
|
pybin = conf.env['PYTHON']
|
|
|
|
if not pybin:
|
|
|
|
conf.fatal('could not find the python executable')
|
|
|
|
|
|
|
|
# Get python version string
|
|
|
|
cmd = pybin + ['-c', 'import sys\nfor x in sys.version_info: print(str(x))']
|
2012-06-01 04:26:44 +02:00
|
|
|
Logs.debug('python: Running python command %r' % cmd)
|
2011-09-10 11:13:51 +02:00
|
|
|
lines = conf.cmd_and_log(cmd).split()
|
|
|
|
assert len(lines) == 5, "found %i lines, expected 5: %r" % (len(lines), lines)
|
|
|
|
pyver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]), lines[3], int(lines[4]))
|
|
|
|
|
|
|
|
# compare python version with the minimum required
|
|
|
|
result = (minver is None) or (pyver_tuple >= minver)
|
|
|
|
|
|
|
|
if result:
|
|
|
|
# define useful environment variables
|
|
|
|
pyver = '.'.join([str(x) for x in pyver_tuple[:2]])
|
|
|
|
conf.env['PYTHON_VERSION'] = pyver
|
|
|
|
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
if 'PYTHONDIR' in conf.env:
|
|
|
|
# Check if --pythondir was specified
|
|
|
|
pydir = conf.env['PYTHONDIR']
|
|
|
|
elif 'PYTHONDIR' in conf.environ:
|
|
|
|
# Check environment for PYTHONDIR
|
2011-09-10 11:13:51 +02:00
|
|
|
pydir = conf.environ['PYTHONDIR']
|
|
|
|
else:
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
# Finally, try to guess
|
2011-09-10 11:13:51 +02:00
|
|
|
if Utils.is_win32:
|
2011-12-17 23:07:25 +01:00
|
|
|
(python_LIBDEST, pydir) = conf.get_python_variables(
|
|
|
|
["get_config_var('LIBDEST') or ''",
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
"get_python_lib(standard_lib=0) or ''"])
|
2011-09-10 11:13:51 +02:00
|
|
|
else:
|
|
|
|
python_LIBDEST = None
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
(pydir,) = conf.get_python_variables( ["get_python_lib(standard_lib=0) or ''"])
|
2011-09-10 11:13:51 +02:00
|
|
|
if python_LIBDEST is None:
|
|
|
|
if conf.env['LIBDIR']:
|
|
|
|
python_LIBDEST = os.path.join(conf.env['LIBDIR'], "python" + pyver)
|
|
|
|
else:
|
|
|
|
python_LIBDEST = os.path.join(conf.env['PREFIX'], "lib", "python" + pyver)
|
|
|
|
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
if 'PYTHONARCHDIR' in conf.env:
|
|
|
|
# Check if --pythonarchdir was specified
|
|
|
|
pyarchdir = conf.env['PYTHONARCHDIR']
|
|
|
|
elif 'PYTHONARCHDIR' in conf.environ:
|
|
|
|
# Check environment for PYTHONDIR
|
2011-09-10 11:13:51 +02:00
|
|
|
pyarchdir = conf.environ['PYTHONARCHDIR']
|
|
|
|
else:
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
# Finally, try to guess
|
|
|
|
(pyarchdir, ) = conf.get_python_variables( ["get_python_lib(plat_specific=1, standard_lib=0) or ''"])
|
2011-09-10 11:13:51 +02:00
|
|
|
if not pyarchdir:
|
|
|
|
pyarchdir = pydir
|
|
|
|
|
|
|
|
if hasattr(conf, 'define'): # conf.define is added by the C tool, so may not exist
|
|
|
|
conf.define('PYTHONDIR', pydir)
|
|
|
|
conf.define('PYTHONARCHDIR', pyarchdir)
|
|
|
|
|
|
|
|
conf.env['PYTHONDIR'] = pydir
|
|
|
|
conf.env['PYTHONARCHDIR'] = pyarchdir
|
|
|
|
|
|
|
|
# Feedback
|
|
|
|
pyver_full = '.'.join(map(str, pyver_tuple[:3]))
|
|
|
|
if minver is None:
|
|
|
|
conf.msg('Checking for python version', pyver_full)
|
|
|
|
else:
|
|
|
|
minver_str = '.'.join(map(str, minver))
|
|
|
|
conf.msg('Checking for python version', pyver_tuple, ">= %s" % (minver_str,) and 'GREEN' or 'YELLOW')
|
|
|
|
|
|
|
|
if not result:
|
|
|
|
conf.fatal('The python version is too old, expecting %r' % (minver,))
|
|
|
|
|
|
|
|
PYTHON_MODULE_TEMPLATE = '''
|
2012-01-14 16:35:33 +01:00
|
|
|
import %s as current_module
|
|
|
|
version = getattr(current_module, '__version__', None)
|
|
|
|
if version is not None:
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
print(str(version))
|
2012-01-14 16:35:33 +01:00
|
|
|
else:
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
print('unknown version')
|
2011-09-10 11:13:51 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
@conf
|
2012-01-14 16:35:33 +01:00
|
|
|
def check_python_module(conf, module_name, condition=''):
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
|
|
|
Check if the selected python interpreter can import the given python module::
|
|
|
|
|
|
|
|
def configure(conf):
|
|
|
|
conf.check_python_module('pygccxml')
|
2012-01-14 16:35:33 +01:00
|
|
|
conf.check_python_module('re', condition="ver > num(2, 0, 4) and ver <= num(3, 0, 0)")
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
:param module_name: module
|
|
|
|
:type module_name: string
|
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
msg = "Checking for python module '%s'" % module_name
|
2012-01-14 16:35:33 +01:00
|
|
|
if condition:
|
|
|
|
msg = '%s (%s)' % (msg, condition)
|
|
|
|
conf.start_msg(msg)
|
2011-09-10 11:13:51 +02:00
|
|
|
try:
|
2012-01-14 16:35:33 +01:00
|
|
|
ret = conf.cmd_and_log(conf.env['PYTHON'] + ['-c', PYTHON_MODULE_TEMPLATE % module_name])
|
|
|
|
except Exception:
|
2011-09-10 11:13:51 +02:00
|
|
|
conf.end_msg(False)
|
|
|
|
conf.fatal('Could not find the python module %r' % module_name)
|
2012-01-14 16:35:33 +01:00
|
|
|
|
|
|
|
ret = ret.strip()
|
|
|
|
if condition:
|
|
|
|
conf.end_msg(ret)
|
|
|
|
if ret == 'unknown version':
|
|
|
|
conf.fatal('Could not check the %s version' % module_name)
|
|
|
|
|
|
|
|
from distutils.version import LooseVersion
|
|
|
|
def num(*k):
|
|
|
|
if isinstance(k[0], int):
|
|
|
|
return LooseVersion('.'.join([str(x) for x in k]))
|
|
|
|
else:
|
|
|
|
return LooseVersion(k[0])
|
|
|
|
d = {'num': num, 'ver': LooseVersion(ret)}
|
|
|
|
ev = eval(condition, {}, d)
|
|
|
|
if not ev:
|
|
|
|
conf.fatal('The %s version does not satisfy the requirements' % module_name)
|
|
|
|
else:
|
|
|
|
if ret == 'unknown version':
|
|
|
|
conf.end_msg(True)
|
|
|
|
else:
|
|
|
|
conf.end_msg(ret)
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
def configure(conf):
|
|
|
|
"""
|
|
|
|
Detect the python interpreter
|
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
v = conf.env
|
2013-09-04 06:35:49 +02:00
|
|
|
v['PYTHON'] = Options.options.python or os.environ.get('PYTHON', sys.executable)
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
if Options.options.pythondir:
|
|
|
|
v['PYTHONDIR'] = Options.options.pythondir
|
|
|
|
if Options.options.pythonarchdir:
|
|
|
|
v['PYTHONARCHDIR'] = Options.options.pythonarchdir
|
2011-09-10 11:13:51 +02:00
|
|
|
|
2013-09-04 06:35:49 +02:00
|
|
|
conf.find_program('python', var='PYTHON')
|
2011-09-10 11:13:51 +02:00
|
|
|
|
|
|
|
v['PYFLAGS'] = ''
|
|
|
|
v['PYFLAGS_OPT'] = '-O'
|
|
|
|
|
|
|
|
v['PYC'] = getattr(Options.options, 'pyc', 1)
|
|
|
|
v['PYO'] = getattr(Options.options, 'pyo', 1)
|
|
|
|
|
2014-07-25 18:15:23 +02:00
|
|
|
try:
|
|
|
|
v.PYTAG = conf.cmd_and_log(conf.env.PYTHON + ['-c', "import imp;print(imp.get_tag())"]).strip()
|
|
|
|
except Errors.WafError:
|
|
|
|
pass
|
|
|
|
|
2011-09-10 11:13:51 +02:00
|
|
|
def options(opt):
|
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
Add python-specific options
|
2011-09-10 11:13:51 +02:00
|
|
|
"""
|
Tools/python: Extending python tool
add: show more command-line arguments to control which
python is used and where py/pyext files should be installed.
The new options are in addition to the existing PYTHON, PYTHONDIR,
and PYTHONARCHDIR environment variable, providing the help messages
to the user, so it can easily change parameters without second-guessing
of what are they.
Environmental parameters override command line arguments (is it right?)
updated: An extension to Configure.find_command to allow specification
of the name for the searched command (using `msg` option). This is
helpful when the search command is a huge list, as in the case of
python's python-config case.
updated: Do not specify prefix for `get_python_lib`, since this way it
can result in a wrong PYTHONDIR and PYTHONARCHDIR on certain platforms
(e.g., OSX)
updated: Changing logic with byte-compilation of python files. Mow, files are
compiled during the build stage, not install stage. During the
install stage files are simply copied to the requested
location.
updated: If there is an error in python source code, byte-compilation
phase will raise an exception and abort building process.
Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
2013-07-12 08:15:35 +02:00
|
|
|
pyopt=opt.add_option_group("Python Options")
|
|
|
|
pyopt.add_option('--nopyc', dest = 'pyc', action='store_false', default=1,
|
|
|
|
help = 'Do not install bytecode compiled .pyc files (configuration) [Default:install]')
|
|
|
|
pyopt.add_option('--nopyo', dest='pyo', action='store_false', default=1,
|
|
|
|
help='Do not install optimised compiled .pyo files (configuration) [Default:install]')
|
|
|
|
pyopt.add_option('--python', dest="python",
|
|
|
|
help='python binary to be used [Default: %s]' % sys.executable)
|
|
|
|
pyopt.add_option('--pythondir', dest='pythondir',
|
|
|
|
help='Installation path for python modules (py, platform-independent .py and .pyc files)')
|
|
|
|
pyopt.add_option('--pythonarchdir', dest='pythonarchdir',
|
|
|
|
help='Installation path for python extension (pyext, platform-dependent .so or .dylib files)')
|
2014-07-25 18:15:23 +02:00
|
|
|
|