version.cpp 2.43 KB
Newer Older
André Anjos's avatar
André Anjos committed
1 2 3 4 5 6 7 8
/**
 * @author Andre Anjos <andre.anjos@idiap.ch>
 * @date Thu  7 Nov 13:50:16 2013
 *
 * @brief Binds configuration information available from bob
 */


9 10 11
#define BOB_IMPORT_VERSION
#include <bob.blitz/config.h>
#include <bob.blitz/cleanup.h>
12
#include <bob.core/config.h>
André Anjos's avatar
André Anjos committed
13 14
#include <bob.io.base/config.h>
#include <bob.learn.libsvm/config.h>
André Anjos's avatar
André Anjos committed
15 16 17 18 19 20 21

static PyObject* build_version_dictionary() {

  PyObject* retval = PyDict_New();
  if (!retval) return 0;
  auto retval_ = make_safe(retval);

22
  if (!dict_steal(retval, "Blitz++", blitz_version())) return 0;
23
  if (!dict_steal(retval, "LIBSVM", get_libsvm_version())) return 0;
André Anjos's avatar
André Anjos committed
24 25 26 27
  if (!dict_steal(retval, "Boost", boost_version())) return 0;
  if (!dict_steal(retval, "Compiler", compiler_version())) return 0;
  if (!dict_steal(retval, "Python", python_version())) return 0;
  if (!dict_steal(retval, "NumPy", numpy_version())) return 0;
28
  if (!dict_steal(retval, "HDF5", hdf5_version())) return 0;
André Anjos's avatar
André Anjos committed
29
  if (!dict_steal(retval, "bob.blitz", bob_blitz_version())) return 0;
30
  if (!dict_steal(retval, "bob.core", bob_core_version())) return 0;
André Anjos's avatar
André Anjos committed
31
  if (!dict_steal(retval, "bob.io.base", bob_io_base_version())) return 0;
André Anjos's avatar
André Anjos committed
32

33
  return Py_BuildValue("O", retval);
André Anjos's avatar
André Anjos committed
34 35 36 37 38 39 40 41 42 43 44 45 46
}

static PyMethodDef module_methods[] = {
    {0}  /* Sentinel */
};

PyDoc_STRVAR(module_docstr,
"Information about software used to compile the C++ Bob API"
);

#if PY_VERSION_HEX >= 0x03000000
static PyModuleDef module_definition = {
  PyModuleDef_HEAD_INIT,
André Anjos's avatar
André Anjos committed
47
  BOB_EXT_MODULE_NAME,
André Anjos's avatar
André Anjos committed
48 49 50 51 52 53 54 55 56 57 58 59
  module_docstr,
  -1,
  module_methods,
  0, 0, 0, 0
};
#endif

static PyObject* create_module (void) {

# if PY_VERSION_HEX >= 0x03000000
  PyObject* m = PyModule_Create(&module_definition);
# else
André Anjos's avatar
André Anjos committed
60
  PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
André Anjos's avatar
André Anjos committed
61 62 63 64 65
# endif
  if (!m) return 0;
  auto m_ = make_safe(m); ///< protects against early returns

  /* register version numbers and constants */
66 67
  if (PyModule_AddIntConstant(m, "api", BOB_LEARN_LIBSVM_API_VERSION) < 0) return 0;
  if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;
André Anjos's avatar
André Anjos committed
68 69 70 71 72

  PyObject* externals = build_version_dictionary();
  if (!externals) return 0;
  if (PyModule_AddObject(m, "externals", externals) < 0) return 0;

73 74
  // call bob_learn_libsvm_version once to avoid compiler warnings
  auto _ = make_safe(bob_learn_libsvm_version());
André Anjos's avatar
André Anjos committed
75

76
  return Py_BuildValue("O", m);
André Anjos's avatar
André Anjos committed
77 78
}

André Anjos's avatar
André Anjos committed
79
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
André Anjos's avatar
André Anjos committed
80 81 82 83 84
# if PY_VERSION_HEX >= 0x03000000
  return
# endif
    create_module();
}