Skip to content

Commit

Permalink
#545: Compare Python/NumPy versions from configure time against those…
Browse files Browse the repository at this point in the history
… loaded at runtime
  • Loading branch information
PhilMiller committed Jul 14, 2023
1 parent b466c5b commit 08d10b3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/utilities/python/InterpreterUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ namespace utils {
addToPath(std::string(py::str(opt.attr("parent"))));
addToPath(std::string(py::str(opt)));
}

py::object python_version_info = importedTopLevelModules["sys"].attr("version_info");
py::str runtime_python_version = importedTopLevelModules["sys"].attr("version");
int major = py::int_(python_version_info.attr("major"));
int minor = py::int_(python_version_info.attr("minor"));
int patch = py::int_(python_version_info.attr("micro"));
if (major != python_major
|| minor != python_minor
|| patch != python_patch) {
throw std::runtime_error("Python version mismatch between configure/build ("
+ std::string(python_version)
+ ") and runtime (" + std::string(runtime_python_version) + ")");
}

importTopLevelModule("numpy");
py::str runtime_numpy_version = importedTopLevelModules["numpy"].attr("version").attr("version");
if(std::string(runtime_numpy_version) != numpy_version) {
throw std::runtime_error("NumPy version mismatch between configure/build ("
+ std::string(numpy_version)
+ ") and runtime (" + std::string(runtime_numpy_version) + ")");
}
}

~InterpreterUtil() = default;
Expand Down

0 comments on commit 08d10b3

Please sign in to comment.