Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit d9e9a61

Browse files
committed
More fixes due to pybind11 v1.3
1 parent b7006a4 commit d9e9a61

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/menu.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ void Menu::build(){
356356
}
357357
}
358358
if(menu != nullptr) {
359+
PythonInterpreter::get();
359360
for (auto &plugin : plugin_entries) {
360361
add_sections(*menu, plugin, accels);
361362
}

src/python_interpreter.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ bool PythonInterpreter::reload(const std::string &module_name){
2121
return false;
2222
}
2323

24+
pybind11::module PythonInterpreter::import(const std::string &module_name){
25+
pybind11::module module(PyImport_ImportModule(module_name.c_str()), true);
26+
if(module){
27+
return module;
28+
}
29+
handle_py_exception();
30+
return pybind11::module(Py_None, false);
31+
}
32+
2433
PythonInterpreter::PythonInterpreter(){
2534
#ifdef _WIN32
2635
auto root_path=Config::get().terminal.msys2_mingw_path;
@@ -41,11 +50,10 @@ PythonInterpreter::PythonInterpreter(){
4150
PySys_SetArgv(0,&argv);
4251
boost::filesystem::directory_iterator end_it;
4352
for(boost::filesystem::directory_iterator it(plugin_path);it!=end_it;it++){
44-
auto module_name = it->path().stem().generic_string();
45-
if(module_name != "__pycache__")
46-
try{
47-
pybind11::module::import(module_name.c_str());
48-
} catch (const std::exception &ex) { }
53+
auto module_name=it->path().stem().generic_string();
54+
if(module_name!="__pycache__"){
55+
auto module=import(module_name);
56+
}
4957
}
5058
}
5159

src/python_interpreter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class PythonInterpreter {
1515
bool reload(const std::string &module_name);
1616
bool parse_syntax_error(pybind11::object &py_value,std::string &error_msgs,std::string &error,int &line_number,int &offset);
1717
void handle_py_exception(bool suppress_error_messages=false);
18+
pybind11::module import(const std::string &module_name);
1819
private:
1920
PythonInterpreter();
2021
wchar_t *argv;

0 commit comments

Comments
 (0)