From 3dc72d18e9c62f61304db5c189de66e4a8b22d9e Mon Sep 17 00:00:00 2001 From: Andre Anjos <andre.anjos@idiap.ch> Date: Mon, 4 Aug 2014 16:55:49 +0200 Subject: [PATCH] Do not depend on Bob/C++ anymore --- bob/io/base/cpp/CodecRegistry.cpp | 11 ++++++----- bob/io/base/cpp/HDF5Attribute.cpp | 21 ++++++++++++--------- bob/io/base/cpp/HDF5Dataset.cpp | 24 ++++++++++++++---------- bob/io/base/cpp/HDF5Group.cpp | 14 ++++++++------ bob/io/base/cpp/HDF5Types.cpp | 11 ++++++----- bob/io/base/cpp/HDF5Utils.cpp | 14 ++++++++------ bob/io/base/main.cpp | 8 ++++++++ setup.py | 7 ++++--- 8 files changed, 66 insertions(+), 44 deletions(-) diff --git a/bob/io/base/cpp/CodecRegistry.cpp b/bob/io/base/cpp/CodecRegistry.cpp index 229d580..821ecce 100644 --- a/bob/io/base/cpp/CodecRegistry.cpp +++ b/bob/io/base/cpp/CodecRegistry.cpp @@ -7,15 +7,15 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#include <bob.core/logging.h> + +#include <bob.io.base/CodecRegistry.h> + #include <vector> #include <boost/filesystem.hpp> #include <boost/format.hpp> -#include <bob.io.base/CodecRegistry.h> - -#include <bob/core/logging.h> - boost::shared_ptr<bob::io::base::CodecRegistry> bob::io::base::CodecRegistry::instance() { static boost::shared_ptr<bob::io::base::CodecRegistry> s_instance(new CodecRegistry()); return s_instance; @@ -58,7 +58,8 @@ void bob::io::base::CodecRegistry::registerExtension(const char* extension, else if (!s_ignore) { boost::format m("extension already registered: %s - ignoring second registration with description `%s'"); m % extension % description; - bob::core::error << m.str() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << m.str() << std::endl; throw std::runtime_error(m.str()); } diff --git a/bob/io/base/cpp/HDF5Attribute.cpp b/bob/io/base/cpp/HDF5Attribute.cpp index e701ace..05d79bc 100644 --- a/bob/io/base/cpp/HDF5Attribute.cpp +++ b/bob/io/base/cpp/HDF5Attribute.cpp @@ -7,12 +7,12 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ -#include <boost/format.hpp> - -#include <bob/core/logging.h> +#include <bob.core/logging.h> #include <bob.io.base/HDF5Attribute.h> +#include <boost/format.hpp> + static std::runtime_error status_error(const char* f, herr_t s) { boost::format m("call to HDF5 C-function %s() returned error %d. HDF5 error statck follows:\n%s"); m % f % s % bob::io::base::format_hdf5_error(); @@ -31,8 +31,9 @@ static void delete_h5dataspace (hid_t* p) { if (*p >= 0) { herr_t err = H5Sclose(*p); if (err < 0) { - bob::core::error << "H5Sclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Sclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -62,8 +63,9 @@ static void delete_h5type (hid_t* p) { if (*p >= 0) { herr_t err = H5Tclose(*p); if (err < 0) { - bob::core::error << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -99,8 +101,9 @@ static void delete_h5attribute (hid_t* p) { if (*p >= 0) { herr_t err = H5Aclose(*p); if (err < 0) { - bob::core::error << "H5Aclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Aclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; diff --git a/bob/io/base/cpp/HDF5Dataset.cpp b/bob/io/base/cpp/HDF5Dataset.cpp index 59b2093..ac0167c 100644 --- a/bob/io/base/cpp/HDF5Dataset.cpp +++ b/bob/io/base/cpp/HDF5Dataset.cpp @@ -7,12 +7,12 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#include <bob.core/logging.h> + #include <boost/format.hpp> #include <boost/make_shared.hpp> #include <boost/shared_array.hpp> -#include <bob/core/logging.h> - #include <bob.io.base/HDF5Utils.h> #include <bob.io.base/HDF5Group.h> #include <bob.io.base/HDF5Dataset.h> @@ -30,8 +30,9 @@ static void delete_h5dataset (hid_t* p) { if (*p >= 0) { herr_t err = H5Dclose(*p); if (err < 0) { - bob::core::error << "H5Dclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Dclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -61,8 +62,9 @@ static void delete_h5datatype (hid_t* p) { if (*p >= 0) { herr_t err = H5Tclose(*p); if (err < 0) { - bob::core::error << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -86,8 +88,9 @@ static void delete_h5plist (hid_t* p) { if (*p >= 0) { herr_t err = H5Pclose(*p); if (err < 0) { - bob::core::error << "H5Pclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Pclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -109,8 +112,9 @@ static void delete_h5dataspace (hid_t* p) { if (*p >= 0) { herr_t err = H5Sclose(*p); if (err < 0) { - bob::core::error << "H5Sclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Sclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; diff --git a/bob/io/base/cpp/HDF5Group.cpp b/bob/io/base/cpp/HDF5Group.cpp index aab9166..43d2c1a 100644 --- a/bob/io/base/cpp/HDF5Group.cpp +++ b/bob/io/base/cpp/HDF5Group.cpp @@ -7,14 +7,14 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#include <bob.core/logging.h> + #include <boost/make_shared.hpp> #include <boost/shared_array.hpp> #include <boost/filesystem.hpp> #include <boost/format.hpp> #include <boost/algorithm/string.hpp> -#include <bob/core/logging.h> - #include <bob.io.base/HDF5Group.h> #include <bob.io.base/HDF5Utils.h> @@ -25,8 +25,9 @@ static void delete_h5g (hid_t* p) { if (*p >= 0) { herr_t err = H5Gclose(*p); if (err < 0) { - bob::core::error << "H5Gclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Gclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -311,8 +312,9 @@ static void delete_h5plist (hid_t* p) { if (*p >= 0) { herr_t err = H5Pclose(*p); if (err < 0) { - bob::core::error << "H5Pclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Pclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; diff --git a/bob/io/base/cpp/HDF5Types.cpp b/bob/io/base/cpp/HDF5Types.cpp index 16795bf..6e79ae1 100644 --- a/bob/io/base/cpp/HDF5Types.cpp +++ b/bob/io/base/cpp/HDF5Types.cpp @@ -7,8 +7,10 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ -#include <boost/format.hpp> +#include <bob.core/logging.h> + #include <sstream> +#include <boost/format.hpp> #include <boost/make_shared.hpp> /** @@ -24,8 +26,6 @@ #warning Disabling MT locks because Boost < 1.35! #endif -#include <bob/core/logging.h> - #include <bob.io.base/HDF5Types.h> const char* bob::io::base::stringize (hdf5type t) { @@ -213,8 +213,9 @@ static void delete_h5datatype (hid_t* p) { if (*p >= 0) { herr_t err = H5Tclose(*p); if (err < 0) { - bob::core::error << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Tclose() exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; diff --git a/bob/io/base/cpp/HDF5Utils.cpp b/bob/io/base/cpp/HDF5Utils.cpp index b735be4..3cbff40 100644 --- a/bob/io/base/cpp/HDF5Utils.cpp +++ b/bob/io/base/cpp/HDF5Utils.cpp @@ -7,11 +7,11 @@ * Copyright (C) Idiap Research Institute, Martigny, Switzerland */ +#include <bob.core/logging.h> + #include <boost/format.hpp> #include <boost/make_shared.hpp> -#include <bob/core/logging.h> - #include <bob.io.base/HDF5Utils.h> /** @@ -21,8 +21,9 @@ static void delete_h5file (hid_t* p) { if (*p >= 0) { herr_t err = H5Fclose(*p); if (err < 0) { - bob::core::error << "H5Fclose(hid=" << *p << ") exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Fclose(hid=" << *p << ") exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; } } delete p; @@ -35,8 +36,9 @@ static void delete_h5p (hid_t* p) { if (*p >= 0) { herr_t err = H5Pclose(*p); if (err < 0) { - bob::core::error << "H5Pclose(hid=" << *p << ") exited with an error (" << err << "). The stack trace follows:" << std::endl; - bob::core::error << bob::io::base::format_hdf5_error() << std::endl; + auto& error_stream = PyBobCoreLogging_Error(); + error_stream << "H5Pclose(hid=" << *p << ") exited with an error (" << err << "). The stack trace follows:" << std::endl; + error_stream << bob::io::base::format_hdf5_error() << std::endl; return; } } diff --git a/bob/io/base/main.cpp b/bob/io/base/main.cpp index f7dfb87..27f18a0 100644 --- a/bob/io/base/main.cpp +++ b/bob/io/base/main.cpp @@ -13,6 +13,7 @@ #endif #include <bob.blitz/capi.h> #include <bob.blitz/cleanup.h> +#include <bob.core/logging.h> /** * Creates an str object, from a C or C++ string. Returns a **new @@ -177,6 +178,13 @@ static PyObject* create_module (void) { if (PyModule_AddObject(m, "_C_API", c_api_object) < 0) return 0; + /* imports dependencies */ + if (import_bob_core_logging() < 0) { + PyErr_Print(); + PyErr_Format(PyExc_ImportError, "cannot import `%s'", BOB_EXT_MODULE_NAME); + return 0; + } + /* imports dependencies */ if (import_bob_blitz() < 0) { PyErr_Print(); diff --git a/setup.py b/setup.py index d3eac6e..58a37d7 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,6 @@ package_dir = os.path.dirname(os.path.realpath(__file__)) package_dir = os.path.join(package_dir, 'bob', 'io', 'base', 'include') include_dirs = [package_dir, bob.core.get_include()] -packages = ['bob-core >= 1.2.2'] version = '2.0.0a0' def libhdf5_version(header): @@ -148,6 +147,7 @@ setup( install_requires=[ 'setuptools', 'bob.blitz', + 'bob.core', ], namespace_packages=[ @@ -160,11 +160,11 @@ setup( [ "bob/io/base/version.cpp", ], - packages = packages, include_dirs = include_dirs, define_macros = define_macros, extra_compile_args = extra_compile_args, version = version, + packages = ['boost'], ), Extension("bob.io.base._library", [ @@ -194,13 +194,14 @@ setup( "bob/io/base/hdf5.cpp", "bob/io/base/main.cpp", ], - packages = packages, include_dirs = include_dirs, library_dirs = library_dirs, libraries = libraries, define_macros = define_macros, extra_compile_args = extra_compile_args, version = version, + packages = ['boost'], + boost_modules = ['iostreams', 'filesystem'], ), ], -- GitLab