Skip to content
Snippets Groups Projects
Commit 3d606ea2 authored by Maxence Naud's avatar Maxence Naud Committed by Maxence Naud
Browse files

update deprecation with pybind override

parent 4b2ea1c2
No related branches found
No related tags found
No related merge requests found
Pipeline #66437 passed
This commit is part of merge request !354. Comments created here will be created in the context of that merge request.
...@@ -43,19 +43,36 @@ static std::string camelToSnakeCase(const std::string &camelCase) { ...@@ -43,19 +43,36 @@ static std::string camelToSnakeCase(const std::string &camelCase) {
#define DEPRECATED_PYBIND(oldName, newName) \ #define DEPRECATED_PYBIND(oldName, newName) \
/* Under PYBIND, if Python is initialized, convert names to snake_case */ \ /* Under PYBIND, if Python is initialized, convert names to snake_case */ \
if (Py_IsInitialized()) { \ if (Py_IsInitialized()) { \
deprecatedFuncNameStr = toSnakeCase(deprecatedFuncNameStr); \ deprecatedFuncNameStr = camelToSnakeCase(oldName); \
newFuncNameStr = toSnakeCase(newFuncNameStr); \ newFuncNameStr = camelToSnakeCase(newName); \
} }
#else #else
#define DEPRECATED_PYBIND(oldName, newName) {} #define DEPRECATED_PYBIND(oldName, newName) do {} while (0)
#endif #endif // PYBIND
// For the C++ interface without Python overrides.
#define DEPRECATED(newFuncName) \ #define DEPRECATED(newFuncName) \
do { \ do { \
std::string deprecatedFuncNameStr(__func__); \ std::string deprecatedFuncNameStr(__func__); \
std::string newFuncNameStr(newFuncName); \ std::string newFuncNameStr(newFuncName); \
DEPRECATED_PYBIND(oldName, newName); \ DEPRECATED_PYBIND(deprecatedFuncNameStr, newFuncName); \
Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", deprecatedFuncNameStr, newFuncNameStr); \ Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", \
deprecatedFuncNameStr, newFuncNameStr); \
} while (0)
// For the case when you want to provide Python-specific override names.
// If PYBIND is detected (and Python is initialized), then the names will be
// replaced as follows:
// deprecatedFuncNameStr = camelToSnakeCase(pybindNewOverridedName)
// newFuncNameStr = camelToSnakeCase(pybindOldOverridedName)
#define DEPRECATED_WITH_PYBIND_OVERRIDES(newFuncName, pybindNewOverridedName, pybindOldOverridedName) \
do { \
std::string deprecatedFuncNameStr(__func__); \
std::string newFuncNameStr(newFuncName); \
/* Swap the order of the override names here */ \
DEPRECATED_PYBIND(pybindNewOverridedName, pybindOldOverridedName); \
Aidge::Log::warn("'{}()' is deprecated, please use '{}()' instead", \
deprecatedFuncNameStr, newFuncNameStr); \
} while (0) } while (0)
#endif // AIDGE_UTILS_DEPRECATED_H_ #endif // AIDGE_UTILS_DEPRECATED_H_
\ No newline at end of file
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