Python API to bob.extension

This section includes information for using the Python API of bob.extension.

A custom build class for Pkg-config based extensions

bob.extension.check_packages(packages)[source]

Checks if the requirements for the given packages are satisfied.

Raises a RuntimeError in case requirements are not satisfied. This means either not finding a package if no version number is specified or verifying that the package version does not match the required version by the builder.

Package requirements can be set like this:

"pkg > VERSION"

In this case, the package version should be greater than the given version number. Comparisons are done using distutils.version.LooseVersion. You can use other comparators such as <, <=, >= or ==. If no version number is given, then we only require that the package is installed.

bob.extension.generate_self_macros(extname, version)[source]

Generates standard macros with library, module names and prefix

bob.extension.reorganize_isystem(args)[source]

Re-organizes the -isystem includes so that more specific paths come first

bob.extension.normalize_requirements(requirements)[source]

Normalizes the requirements keeping only the most tight

class bob.extension.Extension(*args, **kwargs)[source]

Bases: distutils.extension.Extension

Extension building with pkg-config packages.

See the documentation for distutils.extension.Extension for more details on input parameters.

Initialize the extension with parameters.

External package extensions (mostly comming from pkg-config), adds a single parameter to the standard arguments of the constructor:

packages : [list]

This should be a list of strings indicating the name of the bob (pkg-config) modules you would like to have linked to your extension additionally to bob-python. Candidates are module names like “bob-machine” or “bob-math”.

For convenience, you can also specify “opencv” or other ‘pkg-config’ registered packages as a dependencies.

bob.extension.DistutilsExtension

alias of Extension

class bob.extension.boost(requirement='')

A class for capturing configuration information from boost

Example usage:

>>> from bob.extension import boost
>>> pkg = boost('>= 1.35')
>>> pkg.include_directory
'...'
>>> pkg.version
'...'

You can also use this class to retrieve information about installed Boost libraries and link information:

>>> from bob.extension import boost
>>> pkg = boost('>= 1.35')
>>> pkg.libconfig(['python', 'system'])
(...)

Searches for the Boost library in stock locations. Allows user to override.

If the user sets the environment variable BOB_PREFIX_PATH, that prefixes the standard path locations.

libconfig(modules, only_static=False, templates=['boost_%(name)s-mt-%(py)s', 'boost_%(name)s-mt', 'boost_%(name)s'])

Returns a tuple containing the library configuration for requested modules.

This function respects the path location where the include files for Boost are installed.

Parameters:

modules (list of strings)
A list of string specifying the requested libraries to search for. For example, to search for libboost_mpi.so, pass only mpi.
static (bool)
A boolean, indicating if we should try only to search for static versions of the libraries. If not set, any would do.
templates (list of template strings)

A list that defines in which order to search for libraries on the default search path, defined by self.include_directory. Tune this list if you have compiled specific versions of Boost with support to multi-threading (-mt), debug (-g), STLPORT (-p) or required to insert compiler, the underlying thread API used or your own namespace.

Here are the keywords you can use:

%(name)s
resolves to the module name you are searching for
%(ver)s
resolves to the current boost version string (e.g. '1.50.0')
%(py)s
resolves to the string 'pyXY' where XY represent the major and minor versions of the current python interpreter.

Example templates:

  • 'boost_%(name)s-mt'
  • 'boost_%(name)s'
  • 'boost_%(name)s-gcc43-%(ver)s'

Returns:

directories (list of strings)
A list of directories indicating where the libraries are installed
libs (list of strings)
A list of strings indicating the names of the libraries you can use
macros()

Returns package availability and version number macros

This method returns a python list with 2 macros indicating package availability and a version number, using standard GNU compatible names. Example:

>>> from bob.extension import boost
>>> pkg = boost('>= 1.34')
>>> pkg.macros()
[('HAVE_BOOST', '1'), ('BOOST_VERSION', '"..."')]
class bob.extension.pkgconfig(name, paths=None)

A class for capturing configuration information from pkg-config

Example usage:

>>> from bob.extension import pkgconfig
>>> blitz = pkgconfig('blitz')
>>> blitz.include_directories()
[...]
>>> blitz.library_directories()
[...]

If the package does not exist, a RuntimeError is raised. All calls to any methods of a pkgconfig object are translated into a subprocess call that queries for that specific information. If pkg-config fails, a RuntimeError is raised.

Constructor

Parameters:

name
The name of the package of interest, as you would pass on the command line
extra_paths
Search paths to be added to the environment’s PKG_CONFIG_PATH to search for packages.

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config <name>
cflags_other()

Returns a pre-processed dictionary containing compilation options.

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --cflags-only-other <name>

The returned dictionary contains two entries extra_compile_args and define_macros. The define_macros entries are ready for deployment in the setup() function of your package.

Returns a pre-processed list containing extra link arguments.

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --libs-only-other <name>
include_directories()

Returns a pre-processed list containing include directories.

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --cflags-only-I <name>
libraries()

Returns a pre-processed list containing libraries to link against

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --libs-only-l <name>
library_directories()

Returns a pre-processed list containing library directories.

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --libs-only-L <name>
package_macros()

Returns package availability and version number macros

This method returns a python list with 2 macros indicating package availability and a version number, using standard GNU compatible names. For example, if the package is named foo and its version is 1.4, this command would return:

>>> from bob.extension import pkgconfig
>>> blitz = pkgconfig('blitz')
>>> blitz.package_macros()
[('HAVE_BLITZ', '1'), ('BLITZ_VERSION', '"..."')]
variable(name)

Returns a variable with a specific name (if it exists)

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --variable=<variable-name> <name>

Warning

If a variable does not exist in a package, pkg-config does not signal an error. Instead, it returns an empty string. So, do we.

variable_names()

Returns a list with all variable names know to this package

Equivalent command line version:

$ PKG_CONFIG_PATH=<paths> pkg-config --print-variables <name>
bob.extension.uniq(seq)

Uniqu-fy preserving order

bob.extension.get_config()[source]

Returns a string containing the configuration information.

Previous topic

Bob Satellite Package Development and Maintenance

Next topic

Blitz++/Python Arrays

This Page