Utilities for compiling other modules (tomographer.include)¶
The convenience module tomographer.include facilitates the development of new Python/C++ modules using tomographer along with tomographerpy headers.
-
tomographer.include.
get_include
(keys=False)¶ Return the directory(ies) to add to C++ include path in order to compile extensions using tomographer/tomographerpy headers. This function is intended to be used in your setup.py in order to compile your extension.
Tomographer’s dependencies, the Eigen and Boost headers, are included in the package data so that you can easily compile other extensions using Tomographer. This function will also return the necessary include paths to reach those dependencies. (Note: Only a subset of the boost headers are included, as defined by
BOOST_DEPS_COMPONENTS
).If keys=False (the default), then a list of include paths are returned. If keys=True, then a dictionary is returned with the keys [‘tomographer’, ‘tomographerpy’, ‘boost’, ‘eigen’] and with corresponding values which are the include paths for each component.
See also: Information about compile flags in
tomographer.version.compile_info['cflags']
.
-
tomographer.include.
BOOST_DEPS_COMPONENTS
= ['algorithm', 'math', 'core', 'exception', 'predef', 'serialization']¶ Those components of boost which are included in the header dependencies directory of this package.
-
tomographer.include.
find_include_dir
(headername, pkgnames=[], testfn=<function isdir>, return_with_suffix=None, add_paths=[])¶ Find an include directory for a third-party library.
This function works by looking for headername using the test function testfn. By default, it looks for a directory named headername.
Arguments:
- headername: file or directory name to look for
- pkgnames: package names under which these headers may have been packaged, e.g., by homebrew. This is used to add guess paths.
- testfn: how to determine that headername was found. The default,
os.path.isdir()
, checks that headername is a directory. - return_with_suffix: you may set this to a path fragment to be appended to the directory found
- add_paths: additional search paths to use
Returns: The directory relative to which we found headername, possibly supplemented by the given suffix in return_with_suffix. None is returned if the include files were not found.
-
tomographer.include.
find_lib
(libname, pkgnames, libnamesuffixes=[], add_paths=[], prefer_static=True)¶ Find a third-party library.
This function looks for the library libname using common library naming schemes (e.g. lib`libname`.dylib) in common search paths.
Returns the full path to the library or None if not found.
Arguments:
- libname: the base name of the library, without any
lib
prefix or any suffix - pkgnames: as for
find_include_dir()
, specify possible package names which may contain this library - libnamesuffixes: possible library suffixes for libname (but not filename suffix). This is used for instance some times to distinguish a multithreaded version of a library from a non-multithreaded one)
- add_paths: additional paths in which to look
- prefer_static: if True, then static library suffixes are tried before the dynamic ones; if False, the opposite.
- libname: the base name of the library, without any
-
class
tomographer.include.
Vars
(vars, **kwargs)¶ Bases:
object
Minimal handling of compilation config variables, importable from CMake cache.
- Constructor arguments:
- vars: the list of variable names which we will be storing.
- cachefile: a CMake cache file to look values into. If None, no CMake cache is consulted.
- The variables are looked up:
- in the environment variables
- in the CMake cache, if any is specified
- as per any given default value (with
setDefault()
))
Example usage:
cmake_cache_file = os.environ.get('CMAKE_CACHE_FILE', None) vv = Vars([ 'GIT', 'EIGEN3_INCLUDE_DIR', ], cachefile=cmake_cache_file) vv.setDefault('GIT', lambda : find_executable('git')) vv.setDefault('EIGEN3_INCLUDE_DIR', lambda : find_include_dir('eigen3', pkgnames=['eigen','eigen3'], return_with_suffix='eigen3'))
-
get
(k)¶ Get the value associated with the variable k (specified in environment, read from cache, or default value).
-
setDefault
(k, defvalue)¶ If no value has been detected for key k, set the value defvalue. defvalue may be a callable which is invoked only if the value is actually needed.
-
tomographer.include.
ensure_str
(s)¶ Simple conversion of the value s to a str, that is, a byte string on Python 2 and a unicode string on Python 3.
Input is expected to be a byte-string or unicode string in both Py2 or Py3.