Checking compatibility between 'pyopenvino' and 'libopenvino' (#10668)

* Checking compatibility between 'pyopenvino' and 'libopenvino' on 'import phase'

This fix is to prevent undefined behavior when user loads OpenVINO from python, but pyopenvino loads different version of 'libopenvino'
This may happen if user has several releases installed and played around PATH/PYTHONPATH environment variables.

In such case, user may have undefined behavior - application may crash in the middle of the usage or use incorrect release.

Fix checks build versions for pyopenvino and ov::get_openvino_version. If mismatch occurs, exception is thrown.

This logic is disabled if user has built OpenVINO locally, experienced developers probably know what they're doing, so if version has 'custom_'  prefix - this logic is disabled

* Removed custom logic for CI_BUILD_NUMBER, it is reused from already included version.cmake

* Use addVersionDefines macro
This commit is contained in:
Mikhail Nosov 2022-02-28 17:04:59 +03:00 committed by GitHub
parent b319acc672
commit 173f328c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -78,6 +78,8 @@ endif()
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..")
target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB}) target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime ${OFFLINE_TRANSFORMATIONS_LIB})
addVersionDefines(pyopenvino.cpp CI_BUILD_NUMBER)
# perform copy # perform copy
if(OpenVINO_SOURCE_DIR) if(OpenVINO_SOURCE_DIR)
add_custom_command(TARGET ${PROJECT_NAME} add_custom_command(TARGET ${PROJECT_NAME}

View File

@ -69,6 +69,21 @@ std::string get_version() {
PYBIND11_MODULE(pyopenvino, m) { PYBIND11_MODULE(pyopenvino, m) {
m.doc() = "Package openvino.pyopenvino which wraps openvino C++ APIs"; m.doc() = "Package openvino.pyopenvino which wraps openvino C++ APIs";
std::string pyopenvino_version = CI_BUILD_NUMBER;
std::string runtime_version = get_version();
bool is_custom_pyopenvino_version = pyopenvino_version.empty() || pyopenvino_version.find("custom_") == 0;
bool is_custom_runtime_version = runtime_version.empty() || runtime_version.find("custom_") == 0;
auto versions_compatible =
is_custom_pyopenvino_version || is_custom_runtime_version || pyopenvino_version == runtime_version;
OPENVINO_ASSERT(versions_compatible,
"OpenVINO Python version (",
pyopenvino_version,
") mismatches with OpenVINO Runtime library version (",
runtime_version,
"). It can happen if you have 2 or more different versions of OpenVINO installed in system. "
"Please ensure that environment variables (e.g. PATH, PYTHONPATH) are set correctly so that "
"OpenVINO Runtime and Python libraries point to same release.");
m.def("get_version", &get_version); m.def("get_version", &get_version);
m.def("get_batch", &ov::get_batch); m.def("get_batch", &ov::get_batch);
m.def("set_batch", &ov::set_batch); m.def("set_batch", &ov::set_batch);