Commit 3878cd0d authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'python-module-load-verbose'

ea6cc393 Check SMTK_PYTHON_MODULE_LOAD_VERBOSE env when loading py modules
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !2260
parents 3649ec71 ea6cc393
......@@ -50,6 +50,7 @@ SMTK_THIRDPARTY_POST_INCLUDE
// if it is not included before the stl headers our header file includes.
#include "smtk/common/PythonInterpreter.h"
#include "smtk/common/Environment.h"
#include "smtk/common/Paths.h"
#include <cstdlib>
......@@ -258,9 +259,17 @@ bool PythonInterpreter::canFindModule(const std::string& module) const
std::stringstream testCmd;
testCmd << "found = True\n"
<< "try:\n"
<< " import " << module << "\n"
<< "except ImportError:\n"
<< " found = False";
<< " import " << module << "\n";
if (Environment::hasVariable("SMTK_PYTHON_MODULE_LOAD_VERBOSE"))
{
testCmd << "except ImportError as error:\n"
<< " print(str(error))\n";
}
else
{
testCmd << "except ImportError:\n";
}
testCmd << " found = False";
pybind11::exec(testCmd.str().c_str(), pybind11::globals(), locals);
found = locals["found"].cast<bool>();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment