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

Commit d30889c

Browse files
committed
Hook everything up
1 parent 9bdc0c9 commit d30889c

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/config.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void Config::find_or_create_config_files() {
6262
auto config_json = config_dir/"config.json";
6363

6464
boost::filesystem::create_directories(config_dir); // io exp captured by calling method
65+
boost::filesystem::create_directories(home/"plugins");
6566

6667
if (!boost::filesystem::exists(config_json))
6768
filesystem::write(config_json, configjson);
@@ -117,6 +118,8 @@ void Config::retrieve_config() {
117118
terminal.clang_format_command="/usr/bin/clang-format-3.5";
118119
}
119120
#endif
121+
python.plugin_directory=cfg.get<std::string>("python.plugin_directory",(home/"plugins").string());
122+
python.site_packages=cfg.get<std::string>("python.site_packages","/usr/lib/python3.5/site-packages");
120123
}
121124

122125
bool Config::add_missing_nodes(const boost::property_tree::ptree &default_cfg, std::string parent_path) {

src/config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class Config {
7171

7272
std::unordered_map<std::string, DocumentationSearch> documentation_searches;
7373
};
74+
75+
class Python {
76+
public:
77+
std::string site_packages;
78+
std::string plugin_directory;
79+
};
7480
private:
7581
Config();
7682
public:
@@ -86,6 +92,7 @@ class Config {
8692
Terminal terminal;
8793
Project project;
8894
Source source;
95+
Python python;
8996

9097
const boost::filesystem::path& juci_home_path() const { return home; }
9198

src/juci.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "menu.h"
66
#include "config.h"
77
#include "logging.h"
8+
#include "python_interpreter.h"
89

910
int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
1011
Glib::set_prgname("juci");
@@ -112,6 +113,7 @@ void Application::on_startup() {
112113
set_app_menu(Menu::get().juci_menu);
113114
set_menubar(Menu::get().window_menu);
114115
}
116+
PythonInterpreter::get();
115117
}
116118

117119
Application::Application() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) {

src/python_interpreter.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ PythonInterpreter::PythonInterpreter(){
2626
PyImport_AppendInittab("jucipp", init_juci_api);
2727
Py_Initialize();
2828
Config::get().load();
29+
30+
auto plugin_path=Config::get().python.plugin_directory;
31+
add_path(Config::get().python.site_packages);
32+
add_path(plugin_path);
33+
34+
boost::filesystem::directory_iterator end_it;
35+
for(boost::filesystem::directory_iterator it(plugin_path);it!=end_it;it++){
36+
auto module_name=it->path().stem().string();
37+
if(module_name!="__pycache__"){
38+
auto module=import(module_name);
39+
if(!module){
40+
auto err=PythonError();
41+
if(err)
42+
std::cerr << std::string(err) << std::endl;
43+
}
44+
}
45+
}
2946
}
3047

3148
pybind11::module PythonInterpreter::get_loaded_module(const std::string &module_name){

0 commit comments

Comments
 (0)