Skip to content
Snippets Groups Projects
Commit 558f8e8e authored by Manuel Günther's avatar Manuel Günther
Browse files

Applied new versioning system; changed to bob.extension.get_config

parent d1e2c47d
No related branches found
No related tags found
No related merge requests found
...@@ -9,20 +9,9 @@ def get_config(): ...@@ -9,20 +9,9 @@ def get_config():
"""Returns a string containing the configuration information. """Returns a string containing the configuration information.
""" """
import pkg_resources import bob.extension
from .version import externals return bob.extension.get_config(__name__, version.externals)
packages = pkg_resources.require(__name__)
this = packages[0]
deps = packages[1:]
retval = "%s: %s (%s)\n" % (this.key, this.version, this.location)
retval += " - c/c++ dependencies:\n"
for k in sorted(externals): retval += " - %s: %s\n" % (k, externals[k])
retval += " - python dependencies:\n"
for d in deps: retval += " - %s: %s (%s)\n" % (d.key, d.version, d.location)
return retval.strip()
# gets sphinx autodoc done right - don't remove it # gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')] __all__ = [_ for _ in dir() if not _.startswith('_')]
...@@ -31,6 +20,5 @@ __all__ = [_ for _ in dir() if not _.startswith('_')] ...@@ -31,6 +20,5 @@ __all__ = [_ for _ in dir() if not _.startswith('_')]
from pkg_resources import resource_filename from pkg_resources import resource_filename
import os.path import os.path
from ._library import __set_default_model__ from ._library import __set_default_model__
__set_default_model__(resource_filename(__name__, __set_default_model__(resource_filename(__name__, os.path.join('data', 'flandmark_model.dat')))
os.path.join('data', 'flandmark_model.dat')))
del resource_filename, __set_default_model__, os del resource_filename, __set_default_model__, os
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#endif #endif
#include <bob.blitz/capi.h> #include <bob.blitz/capi.h>
#include <bob.blitz/cleanup.h> #include <bob.blitz/cleanup.h>
#include <bob.core/api.h>
#include <bob.io.base/api.h> #include <bob.io.base/api.h>
#include <bob.extension/documentation.h> #include <bob.extension/documentation.h>
...@@ -74,29 +75,16 @@ static PyObject* create_module (void) { ...@@ -74,29 +75,16 @@ static PyObject* create_module (void) {
if (!m) return 0; if (!m) return 0;
auto m_ = make_safe(m); ///< protects against early returns auto m_ = make_safe(m); ///< protects against early returns
if (PyModule_AddStringConstant(m, "__version__", BOB_EXT_MODULE_VERSION) < 0)
return 0;
/* register the types to python */ /* register the types to python */
Py_INCREF(&PyBobIpFlandmark_Type); Py_INCREF(&PyBobIpFlandmark_Type);
if (PyModule_AddObject(m, "Flandmark", (PyObject *)&PyBobIpFlandmark_Type) < 0) return 0; if (PyModule_AddObject(m, "Flandmark", (PyObject *)&PyBobIpFlandmark_Type) < 0) return 0;
/* imports dependencies */ /* imports dependencies */
if (import_bob_blitz() < 0) { if (import_bob_blitz() < 0) return 0;
PyErr_Print(); if (import_bob_core_logging() < 0) return 0;
PyErr_Format(PyExc_ImportError, "cannot import `%s'", BOB_EXT_MODULE_NAME); if (import_bob_io_base() < 0) return 0;
return 0;
}
if (import_bob_io_base() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", BOB_EXT_MODULE_NAME);
return 0;
}
Py_INCREF(m);
return m;
return Py_BuildValue("O", m);
} }
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) { PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
......
...@@ -5,102 +5,15 @@ ...@@ -5,102 +5,15 @@
* @brief Binds configuration information available from bob * @brief Binds configuration information available from bob
*/ */
#include <Python.h>
#include <string>
#include <cstdlib>
#include <blitz/blitz.h>
#include <boost/preprocessor/stringize.hpp>
#include <boost/version.hpp>
#include <boost/format.hpp>
#include <cv.h>
#ifdef NO_IMPORT_ARRAY #define BOB_IMPORT_VERSION
#undef NO_IMPORT_ARRAY #include <bob.blitz/config.h>
#endif
#include <bob.blitz/capi.h>
#include <bob.blitz/cleanup.h> #include <bob.blitz/cleanup.h>
#include <bob.core/config.h>
#include <bob.io.base/config.h> #include <bob.io.base/config.h>
static int dict_set(PyObject* d, const char* key, const char* value) { #include <cv.h>
PyObject* v = Py_BuildValue("s", value);
if (!v) return 0;
int retval = PyDict_SetItemString(d, key, v);
Py_DECREF(v);
if (retval == 0) return 1; //all good
return 0; //a problem occurred
}
static int dict_steal(PyObject* d, const char* key, PyObject* value) {
if (!value) return 0;
int retval = PyDict_SetItemString(d, key, value);
Py_DECREF(value);
if (retval == 0) return 1; //all good
return 0; //a problem occurred
}
/**
* Describes the version of Boost libraries installed
*/
static PyObject* boost_version() {
boost::format f("%d.%d.%d");
f % (BOOST_VERSION / 100000);
f % (BOOST_VERSION / 100 % 1000);
f % (BOOST_VERSION % 100);
return Py_BuildValue("s", f.str().c_str());
}
/**
* Describes the compiler version
*/
static PyObject* compiler_version() {
# if defined(__GNUC__) && !defined(__llvm__)
boost::format f("%s.%s.%s");
f % BOOST_PP_STRINGIZE(__GNUC__);
f % BOOST_PP_STRINGIZE(__GNUC_MINOR__);
f % BOOST_PP_STRINGIZE(__GNUC_PATCHLEVEL__);
return Py_BuildValue("{ssss}", "name", "gcc", "version", f.str().c_str());
# elif defined(__llvm__) && !defined(__clang__)
return Py_BuildValue("{ssss}", "name", "llvm-gcc", "version", __VERSION__);
# elif defined(__clang__)
return Py_BuildValue("{ssss}", "name", "clang", "version", __clang_version__);
# else
return Py_BuildValue("{ssss}", "name", "unsupported", "version", "unknown");
# endif
}
/**
* Python version with which we compiled the extensions
*/
static PyObject* python_version() {
boost::format f("%s.%s.%s");
f % BOOST_PP_STRINGIZE(PY_MAJOR_VERSION);
f % BOOST_PP_STRINGIZE(PY_MINOR_VERSION);
f % BOOST_PP_STRINGIZE(PY_MICRO_VERSION);
return Py_BuildValue("s", f.str().c_str());
}
/**
* Numpy version
*/
static PyObject* numpy_version() {
return Py_BuildValue("{ssss}", "abi", BOOST_PP_STRINGIZE(NPY_VERSION),
"api", BOOST_PP_STRINGIZE(NPY_API_VERSION));
}
/**
* bob.blitz c/c++ api version
*/
static PyObject* bob_blitz_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_BLITZ_API_VERSION));
}
/**
* bob.io c/c++ api version
*/
static PyObject* bob_io_base_version() {
return Py_BuildValue("{ss}", "api", BOOST_PP_STRINGIZE(BOB_IO_BASE_API_VERSION));
}
static PyObject* build_version_dictionary() { static PyObject* build_version_dictionary() {
...@@ -108,17 +21,18 @@ static PyObject* build_version_dictionary() { ...@@ -108,17 +21,18 @@ static PyObject* build_version_dictionary() {
if (!retval) return 0; if (!retval) return 0;
auto retval_ = make_safe(retval); auto retval_ = make_safe(retval);
if (!dict_set(retval, "OpenCV", CV_VERSION)) return 0; if (!dict_steal(retval, "OpenCV", Py_BuildValue("s", CV_VERSION))) return 0;
if (!dict_set(retval, "Blitz++", BZ_VERSION)) return 0; if (!dict_steal(retval, "Blitz++", blitz_version())) return 0;
if (!dict_steal(retval, "Boost", boost_version())) return 0; if (!dict_steal(retval, "Boost", boost_version())) return 0;
if (!dict_steal(retval, "Compiler", compiler_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, "Python", python_version())) return 0;
if (!dict_steal(retval, "NumPy", numpy_version())) return 0; if (!dict_steal(retval, "NumPy", numpy_version())) return 0;
if (!dict_steal(retval, "HDF5", hdf5_version())) return 0;
if (!dict_steal(retval, "bob.blitz", bob_blitz_version())) return 0; if (!dict_steal(retval, "bob.blitz", bob_blitz_version())) return 0;
if (!dict_steal(retval, "bob.io", bob_io_base_version())) return 0; if (!dict_steal(retval, "bob.core", bob_core_version())) return 0;
if (!dict_steal(retval, "bob.io.base", bob_io_base_version())) return 0;
Py_INCREF(retval); return Py_BuildValue("O", retval);
return retval;
} }
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {
...@@ -151,23 +65,13 @@ static PyObject* create_module (void) { ...@@ -151,23 +65,13 @@ static PyObject* create_module (void) {
auto m_ = make_safe(m); ///< protects against early returns auto m_ = make_safe(m); ///< protects against early returns
/* register version numbers and constants */ /* register version numbers and constants */
if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) if (PyModule_AddStringConstant(m, "module", BOB_EXT_MODULE_VERSION) < 0) return 0;
return 0;
PyObject* externals = build_version_dictionary(); PyObject* externals = build_version_dictionary();
if (!externals) return 0; if (!externals) return 0;
if (PyModule_AddObject(m, "externals", externals) < 0) return 0; if (PyModule_AddObject(m, "externals", externals) < 0) return 0;
/* imports dependencies */ return Py_BuildValue("O", m);
if (import_bob_blitz() < 0) {
PyErr_Print();
PyErr_Format(PyExc_ImportError, "cannot import `%s'", BOB_EXT_MODULE_NAME);
return 0;
}
Py_INCREF(m);
return m;
} }
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) { PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment