From 33713e866c0af925d60d7a0a16d7588b84485116 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Mon, 25 Nov 2019 08:47:46 +0100 Subject: [PATCH] core/version: add version to the module --- CMakeLists.txt | 2 ++ include/eigenpy/fwd.hpp | 2 ++ include/eigenpy/version.hpp | 38 +++++++++++++++++++++++++++++++++++++ src/eigenpy.cpp | 8 ++++++++ src/version.cpp | 30 +++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 include/eigenpy/version.hpp create mode 100644 src/version.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d0346caf..9e36d84a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ SET(${PROJECT_NAME}_HEADERS include/eigenpy/stride.hpp include/eigenpy/ref.hpp include/eigenpy/details/rvalue_from_python_data.hpp + include/eigenpy/version.hpp ) LIST(APPEND ${PROJECT_NAME}_HEADERS @@ -133,6 +134,7 @@ SET(${PROJECT_NAME}_SOURCES src/angle-axis.cpp src/quaternion.cpp src/geometry-conversion.cpp + src/version.cpp ) ADD_LIBRARY(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_SOURCES} ${${PROJECT_NAME}_HEADERS}) diff --git a/include/eigenpy/fwd.hpp b/include/eigenpy/fwd.hpp index d4469498..702b7d43 100644 --- a/include/eigenpy/fwd.hpp +++ b/include/eigenpy/fwd.hpp @@ -6,6 +6,8 @@ #ifndef __eigenpy_fwd_hpp__ #define __eigenpy_fwd_hpp__ +#include "eigenpy/config.hpp" + #include <boost/python.hpp> #include <Eigen/Core> diff --git a/include/eigenpy/version.hpp b/include/eigenpy/version.hpp new file mode 100644 index 00000000..ca389bf6 --- /dev/null +++ b/include/eigenpy/version.hpp @@ -0,0 +1,38 @@ +// +// Copyright (c) 2019 INRIA +// + +#ifndef __eigenpy_version_hpp__ +#define __eigenpy_version_hpp__ + +#include "eigenpy/config.hpp" + +#include <string> + +namespace eigenpy +{ + + /// + /// \brief Returns the current version of EigenPy as a string using + /// the following standard: + /// EIGENPY_MINOR_VERSION.EIGENPY_MINOR_VERSION.EIGENPY_PATCH_VERSION + /// + std::string printVersion(const std::string & delimiter = "."); + + /// + /// \brief Checks if the current version of EigenPy is at least the version provided + /// by the input arguments. + /// + /// \param[in] major_version Major version to check. + /// \param[in] minor_version Minor version to check. + /// \param[in] patch_version Patch version to check. + /// + /// \returns true if the current version of EigenPy is greater than the version provided + /// by the input arguments. + /// + bool checkVersionAtLeast(unsigned int major_version, + unsigned int minor_version, + unsigned int patch_version); +} + +#endif // __eigenpy_version_hpp__ diff --git a/src/eigenpy.cpp b/src/eigenpy.cpp index 9d7490e3..0b55ad6d 100644 --- a/src/eigenpy.cpp +++ b/src/eigenpy.cpp @@ -4,6 +4,7 @@ */ #include "eigenpy/eigenpy.hpp" +#include "eigenpy/version.hpp" namespace eigenpy { @@ -12,6 +13,13 @@ namespace eigenpy void enableEigenPy() { using namespace Eigen; + + bp::scope().attr("__version__") = eigenpy::printVersion(); + bp::scope().attr("__raw_version__") = bp::str(EIGENPY_VERSION); + bp::def("checkVersionAtLeast",&eigenpy::checkVersionAtLeast, + bp::args("major_version","minor_version","patch_version"), + "Checks if the current version of EigenPy is at least the version provided by the input arguments."); + Exception::registerException(); bp::def("setNumpyType",&NumpyType::setNumpyType, diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 00000000..96887634 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,30 @@ +// +// Copyright (c) 2019 INRIA +// + +#include "eigenpy/config.hpp" +#include "eigenpy/version.hpp" + +#include <sstream> + +namespace eigenpy +{ + + std::string printVersion(const std::string & delimiter) + { + std::ostringstream oss; + oss + << EIGENPY_MAJOR_VERSION << delimiter + << EIGENPY_MINOR_VERSION << delimiter + << EIGENPY_PATCH_VERSION; + return oss.str(); + } + + bool checkVersionAtLeast(unsigned int major_version, + unsigned int minor_version, + unsigned int patch_version) + { + return EIGENPY_VERSION_AT_LEAST(major_version,minor_version,patch_version); + } + +} -- GitLab