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

Commit b8625f2

Browse files
committed
Better handling of other files in plugin directory
1 parent 379600b commit b8625f2

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

src/python_interpreter.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ Python::Interpreter::Interpreter(){
8383
boost::filesystem::directory_iterator end_it;
8484
for(boost::filesystem::directory_iterator it(plugin_path);it!=end_it;it++){
8585
auto module_name=it->path().stem().string();
86-
if(module_name!="__pycache__"){
86+
if(module_name.empty())
87+
break;
88+
auto is_directory=boost::filesystem::is_directory(it->path());
89+
auto has_py_extension=it->path().extension()==".py";
90+
auto is_pycache=module_name=="__pycache__";
91+
if((is_directory && !is_pycache)||has_py_extension){
8792
auto module=import(module_name);
8893
if(!module){
8994
auto msg="Error loading plugin `"+module_name+"`:\n";

src/window.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,24 +252,25 @@ void Window::set_menu_actions() {
252252
notebook.configure(c);
253253
}
254254
}
255-
while(file_path.has_parent_path()){
256-
auto parent=file_path.parent_path();
257-
if(parent==Config::get().python.plugin_directory){
258-
auto stem=file_path.stem().string();
259-
auto module=Python::get_loaded_module(stem);
260-
module=module ? Python::reload(module) : Python::import(stem);
261-
if(module)
262-
Terminal::get().print("Plugin `"+stem+"` was reloaded\n");
263-
else {
264-
if(Python::thrown_exception_matches(PyExc_SyntaxError))
265-
Terminal::get().print(Python::SyntaxError());
266-
else
267-
Terminal::get().print(Python::Error());
255+
if(file_path.extension().string()==".py")
256+
while(file_path.has_parent_path()){
257+
auto parent=file_path.parent_path();
258+
if(parent==Config::get().python.plugin_directory){
259+
auto stem=file_path.stem().string();
260+
auto module=Python::get_loaded_module(stem);
261+
module=module ? Python::reload(module) : Python::import(stem);
262+
if(module)
263+
Terminal::get().print("Plugin `"+stem+"` was reloaded\n");
264+
else {
265+
if(Python::thrown_exception_matches(PyExc_SyntaxError))
266+
Terminal::get().print(Python::SyntaxError());
267+
else
268+
Terminal::get().print(Python::Error());
269+
}
270+
break;
268271
}
269-
break;
272+
file_path=parent;
270273
}
271-
file_path=parent;
272-
}
273274
}
274275
}
275276
}

0 commit comments

Comments
 (0)