Python API¶
This section includes information for using the Python API of bob.extension
.
Functions¶
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.
- :param
list
ofstr
: Each representing a requirement that must be statistfied. 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.
Raises: 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.- :param
-
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
-
bob.extension.
get_bob_libraries
(bob_packages)[source]¶ Returns a list of include directories, libraries and library directories for the given bob libraries.
-
bob.extension.
get_full_libname
(name, path=None, version=None)[source]¶ Generates the name of the library from the given name, path and version.
-
bob.extension.
load_bob_library
(name, _file_)[source]¶ Loads the bob Library for the given package name in the given version (if given). The _file_ parameter is expected to be the
__file__
member of the main__init__.py
of the package. It is used to determine the directory, where the library should be loaded from.Keyword parameters
- name : string
- The name of the bob package to load the library from, e.g.
bob.core
- _file_ : string
- The
__file__
member of the__init__.py
file in which the library is loaded.
-
class
bob.extension.
Extension
(name, sources, **kwargs)[source]¶ Bases:
setuptools.extension.Extension
Extension building with pkg-config packages.
See the documentation for
distutils.extension.Extension
for more details on input parameters.
-
class
bob.extension.
Library
(name, sources, version, bob_packages=[], packages=[], boost_modules=[], include_dirs=[], system_include_dirs=[], libraries=[], library_dirs=[], define_macros=[])[source]¶ Bases:
bob.extension.Extension
A class to compile a pure C++ code library used within and outside an extension using CMake.
-
compile
(build_directory, compiler=None, stdout=None)[source]¶ This function will automatically create a CMakeLists.txt file in the
package_directory
including the required information. Afterwards, the library is built using CMake in the givenbuild_directory
. The build type is automatically taken from the debug option in the buildout.cfg. To change the compiler, use thecompiler
parameter.
-
-
class
bob.extension.
CMakeListsGenerator
(name, sources, target_directory, version='1.0.0', include_directories=[], system_include_directories=[], libraries=[], library_directories=[], macros=[])[source]¶ Generates a CMakeLists.txt file for the given sources, include directories and libraries.
-
class
bob.extension.
boost
(requirement='')[source]¶ 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']) (...)
-
libconfig
(modules, only_static=False, templates=['boost_%(name)s-mt-%(py)s', 'boost_%(name)s-%(py)s', 'boost_%(name)s-mt', 'boost_%(name)s'])[source]¶ 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'
whereXY
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
()[source]¶ 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', '"..."')]
-
-
bob.extension.
find_executable
(name, subpaths=None, prefixes=None)[source]¶ Finds an executable on the file system. Returns all candidates.
This method will find all occurrences of a given name on the file system and will return them to the user.
If the environment variable
BOB_PREFIX_PATH
is set, then it is considered a unix path list that is prepended to the list of prefixes to search for. The environment variable has the highest priority on the search order. The order on the variable for each path is respected.Parameters:
- name, str
- The name of the executable to be found.
- subpaths, str list
- A list of subpaths to be appended to each prefix for the search. For
example, if you specificy
['foo', 'bar']
for this parameter, then search onos.path.join(prefixes[0], 'foo')
,os.path.join(prefixes[0], 'bar')
, and so on. - prefixes, str list
- A list of prefixes that will be searched prioritarily to the
DEFAULT_PREFIXES
defined in this module.
Returns a list of filenames that exist on the filesystem, matching your description.
-
bob.extension.
find_library
(name, version=None, subpaths=None, prefixes=None, only_static=False)[source]¶ Finds a library file on the file system. Returns all candidates.
This method will find all occurrences of a given name on the file system and will return them to the user.
If the environment variable
BOB_PREFIX_PATH
is set, then it is considered a unix path list that is prepended to the list of prefixes to search for. The environment variable has the highest priority on the search order. The order on the variable for each path is respected.Parameters:
- name, str
- The name of the module to be found. If you’d like to find libz.so, for
example, specify
"z"
. For libmath.so, specify"math"
. - version, str
- The version of the library we are searching for. If not specified, then
look only for the default names, such as
libz.so
and the such. - subpaths, str list
- A list of subpaths to be appended to each prefix for the search. For
example, if you specificy
['foo', 'bar']
for this parameter, then search onos.path.join(prefixes[0], 'foo')
,os.path.join(prefixes[0], 'bar')
, and so on. - prefixes, str list
- A list of prefixes that will be searched prioritarily to the
DEFAULT_PREFIXES
defined in this module. - static (bool)
- A boolean, indicating if we should try only to search for static versions of the libraries. If not set, any would do.
Returns a list of filenames that exist on the filesystem, matching your description.
-
class
bob.extension.
pkgconfig
(name, paths=None)[source]¶ 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. Ifpkg-config
fails, a RuntimeError is raised.-
cflags_other
()[source]¶ 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
anddefine_macros
. Thedefine_macros
entries are ready for deployment in thesetup()
function of your package.
-
extra_link_args
()[source]¶ 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
()[source]¶ Returns a pre-processed list containing include directories.
Equivalent command line version:
$ PKG_CONFIG_PATH=<paths> pkg-config --cflags-only-I <name>
-
libraries
()[source]¶ 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
()[source]¶ Returns a pre-processed list containing library directories.
Equivalent command line version:
$ PKG_CONFIG_PATH=<paths> pkg-config --libs-only-L <name>
-
other_libraries
()[source]¶ Returns a pre-processed list containing libraries to link against
Equivalent command line version:
$ PKG_CONFIG_PATH=<paths> pkg-config --libs-only-other <name>
-
package_macros
()[source]¶ 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 is1.4
, this command would return:>>> from bob.extension import pkgconfig >>> blitz = pkgconfig('blitz') >>> blitz.package_macros() [('HAVE_BLITZ', '1'), ('BLITZ_VERSION', '"..."')]
-
variable
(name)[source]¶ 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.
-
-
bob.extension.
uniq_paths
(seq)[source]¶ Uniq’fy a list of paths taking into consideration their real paths
-
class
bob.extension.
build_ext
(dist, **kw)[source]¶ Bases:
setuptools.command.build_ext.build_ext
Compile the C++ :py:class`Library`’s using CMake, and the python extensions afterwards
See the documentation for
distutils.command.build_ext
for more information.-
run
()[source]¶ Iterates through the list of Extension packages and reorders them, so that the Library’s come first
-
build_extension
(ext)[source]¶ Builds the given extension.
When the extension is of type Library, it compiles the library with CMake, otherwise the default compilation mechanism is used. Afterwards, it adds the according library, and the include and library directories of the Library’s, so that other Extensions can find the newly generated lib.
-
-
bob.extension.
get_config
(package='bob.extension', externals=None, api_version=None)[source]¶ Returns a string containing the configuration information for the given
package
name. By default, it returns the configuration of this package.This function can be reused by other packages. If these packages have external C or C++ dependencies, the
externals
dictionary can be specified. Also, if the package provides an API version, it can be specified.Keyword parameters:
- package : str
- The name of the package to get the configuration information from.
Usually, the
__name__
of the package. - externals : {dep: description}
- A dictionary of external C or C++ dependencies, with the
dep``endent package name as key, and a free ``description
as value. - api_version : int (usually in hexadecimal)
- The API version of the
package
, if any.