python

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')
waflib.Tools.python.FRAG

Piece of C/C++ code used in waflib.Tools.python.check_python_headers()

waflib.Tools.python.INST

Piece of Python code used in waflib.Tools.python.install_pyfile() for installing python files

waflib.Tools.python.process_py(self, node)[source]

Add a callback using waflib.Tools.python.install_pyfile() to install a python file

waflib.Tools.python.install_pyfile(self, node, install_from=None)[source]

Execute the installation of a python file

Parameters:
waflib.Tools.python.feature_py(self)[source]

Task generator method

Dummy feature which does nothing

Feature :py
waflib.Tools.python.init_pyext(self)[source]

Task generator method

Change the values of cshlib_PATTERN and cxxshlib_PATTERN to remove the lib prefix from library names.

Feature :pyext
waflib.Tools.python.set_bundle(self)[source]
Feature :pyext
waflib.Tools.python.init_pyembed(self)[source]

Task generator method

Add the PYEMBED variable.

Feature :pyembed
waflib.Tools.python.get_python_variables(conf, variables, imports=['import sys'])[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Execute a python interpreter to dump configuration variables

Parameters:
  • variables (list of string) – variables to print
  • imports (list of string) – one import by element
Returns:

the variable values

Return type:

list of string

waflib.Tools.python.check_python_headers(conf)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

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
waflib.Tools.python.check_python_version(conf, minver=None)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

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.

Parameters:
  • minver (tuple of int) – minimum version
waflib.Tools.python.check_python_module(conf, module_name)[source]

Configuration Method bound to waflib.Configure.ConfigurationContext

Check if the selected python interpreter can import the given python module:

def configure(conf):
        conf.check_python_module('pygccxml')
Parameters:
  • module_name (string) – module
waflib.Tools.python.conf(f)

Decorator: attach new configuration functions to waflib.Build.BuildContext and waflib.Configure.ConfigurationContext. The methods bound will accept a parameter named ‘mandatory’ to disable the configuration errors:

def configure(conf):
        conf.find_program('abc', mandatory=False)
Parameters:
  • f (function) – method to bind
waflib.Tools.python.feature(*k)

Decorator: register a task generator method that will be executed when the object attribute ‘feature’ contains the corresponding key(s):

from waflib.Task import feature
@feature('myfeature')
def myfunction(self):
        print('that is my feature!')
def build(bld):
        bld(features='myfeature')
Parameters:
  • k (list of string) – feature names
waflib.Tools.python.before_method(*k)

Decorator: register a task generator method which will be executed before the functions of given name(s):

from waflib.TaskGen import feature, before
@feature('myfeature')
@before_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters:
  • k (list of string) – method names
waflib.Tools.python.configure(conf)[source]

Detect the python interpreter

waflib.Tools.python.after_method(*k)

Decorator: register a task generator method which will be executed after the functions of given name(s):

from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
        print('feature 1!')
@feature('myfeature')
def fun2(self):
        print('feature 2!')
def build(bld):
        bld(features='myfeature')
Parameters:
  • k (list of string) – method names
waflib.Tools.python.warn(*k, **kw)

Wrap logging.warn

waflib.Tools.python.info(*k, **kw)

Wrap logging.info

waflib.Tools.python.extension(*k)

Decorator: register a task generator method which will be invoked during the processing of source files for the extension given:

from waflib import Task
class mytask(Task):
        run_str = 'cp ${SRC} ${TGT}'
@extension('.moo')
def create_maa_file(self, node):
        self.create_task('mytask', node, node.change_ext('.maa'))
def build(bld):
        bld(source='foo.moo')
waflib.Tools.python.error(*k, **kw)

Wrap logging.errors, display the origin of the message when ‘-vv’ is set

waflib.Tools.python.debug(*k, **kw)

Wrap logging.debug, the output is filtered for performance reasons

waflib.Tools.python.options(opt)[source]

Add the options --nopyc and --nopyo

Features defined in this module:

Previous topic

perl

Next topic

ruby

This Page