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

Commit 49d6786

Browse files
committed
Better handling of other files in plugin directory
1 parent a02a014 commit 49d6786

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,26 @@ void Window::set_menu_actions() {
329329
Notebook::get().get_view(c)->configure();
330330
Notebook::get().configure(c);
331331
}
332-
auto file_path=view->file_path;
333-
while(file_path.has_parent_path()){
334-
auto parent=file_path.parent_path();
335-
if(parent==Config::get().python.plugin_directory){
336-
auto stem=file_path.stem().string();
337-
auto module=Python::get_loaded_module(stem);
338-
module=module ? Python::reload(module) : Python::import(stem);
339-
if(module)
340-
Terminal::get().print("Plugin `"+stem+"` was reloaded\n");
341-
else {
342-
if(Python::thrown_exception_matches(PyExc_SyntaxError))
343-
Terminal::get().print(Python::SyntaxError());
344-
else
345-
Terminal::get().print(Python::Error());
332+
if(view->file_path.extension().string()==".py"){
333+
auto file_path=view->file_path;
334+
while(file_path.has_parent_path()){
335+
auto parent=file_path.parent_path();
336+
if(parent==Config::get().python.plugin_directory){
337+
auto stem=file_path.stem().string();
338+
auto module=Python::get_loaded_module(stem);
339+
module=module ? Python::reload(module) : Python::import(stem);
340+
if(module)
341+
Terminal::get().print("Plugin `"+stem+"` was reloaded\n");
342+
else {
343+
if(Python::thrown_exception_matches(PyExc_SyntaxError))
344+
Terminal::get().print(Python::SyntaxError());
345+
else
346+
Terminal::get().print(Python::Error());
347+
}
348+
break;
346349
}
347-
break;
350+
file_path=parent;
348351
}
349-
file_path=parent;
350352
}
351353
}
352354
}

0 commit comments

Comments
 (0)