diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a5c802..64c03c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ set(JUCI_SHARED_FILES usages_clang.cpp utility.cpp python_module.cc + config_module.cc ) if(LIBLLDB_FOUND) list(APPEND JUCI_SHARED_FILES debug_lldb.cpp) diff --git a/src/config.cpp b/src/config.cpp index 771e876..941f77e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -222,108 +222,3 @@ void Config::read(const boost::property_tree::ptree &cfg) { std::cout << "Plugins enabled" << std::endl; } } - -void Config::init_module(py::module &api) { - py::class_> config(api, "Config"); - config - .def(py::init([]() { return &(Config::get()); })) - .def("load", &Config::load) - .def_readonly("version", &Config::version) - - ; - py::class_(config, "Menu") - .def_readwrite("keys", &Config::Menu::keys) - - ; - py::class_(config, "Theme") - .def_readwrite("name", &Config::Theme::name) - .def_readwrite("variant", &Config::Theme::variant) - .def_readwrite("font", &Config::Theme::font) - - ; - py::class_(config, "Terminal") - .def_readwrite("history_size", &Config::Terminal::history_size) - .def_readwrite("font", &Config::Terminal::font) - - ; - py::class_ project(config, "Project"); - py::class_(project, "CMake") - .def_readwrite("command", &Config::Project::CMake::command) - .def_readwrite("compile_command", &Config::Project::CMake::compile_command) - - ; - py::class_(project, "Meson") - .def_readwrite("command", &Config::Project::Meson::command) - .def_readwrite("compile_command", &Config::Project::Meson::compile_command) - - ; - project - .def_readwrite("default_build_path", &Config::Project::default_build_path) - .def_readwrite("debug_build_path", &Config::Project::debug_build_path) - .def_readwrite("cmake", &Config::Project::cmake) - .def_readwrite("meson", &Config::Project::meson) - .def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run) - .def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile) - .def_readwrite("ctags_command", &Config::Project::ctags_command) - .def_readwrite("python_command", &Config::Project::python_command) - - ; - py::class_ source(config, "Source"); - py::class_(source, "DocumentationSearch") - .def_readwrite("separator", &Config::Source::DocumentationSearch::separator) - .def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries) - - ; - source - .def_readwrite("style", &Config::Source::style) - .def_readwrite("font", &Config::Source::font) - .def_readwrite("spellcheck_language", &Config::Source::spellcheck_language) - .def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters) - .def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters) - .def_readwrite("format_style_on_save", &Config::Source::format_style_on_save) - .def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found) - .def_readwrite("smart_inserts", &Config::Source::smart_inserts) - .def_readwrite("show_map", &Config::Source::show_map) - .def_readwrite("map_font_size", &Config::Source::map_font_size) - .def_readwrite("show_git_diff", &Config::Source::show_git_diff) - .def_readwrite("show_background_pattern", &Config::Source::show_background_pattern) - .def_readwrite("show_right_margin", &Config::Source::show_right_margin) - .def_readwrite("right_margin_position", &Config::Source::right_margin_position) - .def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size) - .def_readwrite("default_tab_char", &Config::Source::default_tab_char) - .def_readwrite("default_tab_size", &Config::Source::default_tab_size) - .def_readwrite("tab_indents_line", &Config::Source::tab_indents_line) - .def_readwrite("wrap_lines", &Config::Source::wrap_lines) - .def_readwrite("highlight_current_line", &Config::Source::highlight_current_line) - .def_readwrite("show_line_numbers", &Config::Source::show_line_numbers) - .def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors) - .def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files) - .def_readwrite("clang_format_style", &Config::Source::clang_format_style) - .def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads) - .def_readwrite("documentation_searches", &Config::Source::documentation_searches) - - ; - - py::class_(config, "Log") - .def_readwrite("libclang", &Config::Log::libclang) - .def_readwrite("language_server", &Config::Log::language_server) - - ; - py::class_(config, "Plugins") - .def_readwrite("enabled", &Config::Plugins::enabled) - .def_readwrite("path", &Config::Plugins::path) - - ; - config - .def_readwrite("menu", &Config::menu) - .def_readwrite("theme", &Config::theme) - .def_readwrite("terminal", &Config::terminal) - .def_readwrite("project", &Config::project) - .def_readwrite("source", &Config::source) - .def_readwrite("log", &Config::log) - .def_readwrite("plugins", &Config::plugins) - .def_readwrite("home_path", &Config::home_path) - .def_readwrite("home_juci_path", &Config::home_juci_path) - - ; -} diff --git a/src/config_module.cc b/src/config_module.cc new file mode 100644 index 0000000..54efc7d --- /dev/null +++ b/src/config_module.cc @@ -0,0 +1,106 @@ +#include "config.h" + +void Config::init_module(py::module &api) { + py::class_> config(api, "Config"); + config + .def(py::init([]() { return &(Config::get()); })) + .def("load", &Config::load) + .def_readonly("version", &Config::version) + + ; + py::class_(config, "Menu") + .def_readwrite("keys", &Config::Menu::keys) + + ; + py::class_(config, "Theme") + .def_readwrite("name", &Config::Theme::name) + .def_readwrite("variant", &Config::Theme::variant) + .def_readwrite("font", &Config::Theme::font) + + ; + py::class_(config, "Terminal") + .def_readwrite("history_size", &Config::Terminal::history_size) + .def_readwrite("font", &Config::Terminal::font) + + ; + py::class_ project(config, "Project"); + py::class_(project, "CMake") + .def_readwrite("command", &Config::Project::CMake::command) + .def_readwrite("compile_command", &Config::Project::CMake::compile_command) + + ; + py::class_(project, "Meson") + .def_readwrite("command", &Config::Project::Meson::command) + .def_readwrite("compile_command", &Config::Project::Meson::compile_command) + + ; + project + .def_readwrite("default_build_path", &Config::Project::default_build_path) + .def_readwrite("debug_build_path", &Config::Project::debug_build_path) + .def_readwrite("cmake", &Config::Project::cmake) + .def_readwrite("meson", &Config::Project::meson) + .def_readwrite("save_on_compile_or_run", &Config::Project::save_on_compile_or_run) + .def_readwrite("clear_terminal_on_compile", &Config::Project::clear_terminal_on_compile) + .def_readwrite("ctags_command", &Config::Project::ctags_command) + .def_readwrite("python_command", &Config::Project::python_command) + + ; + py::class_ source(config, "Source"); + py::class_(source, "DocumentationSearch") + .def_readwrite("separator", &Config::Source::DocumentationSearch::separator) + .def_readwrite("compile_command", &Config::Source::DocumentationSearch::queries) + + ; + source + .def_readwrite("style", &Config::Source::style) + .def_readwrite("font", &Config::Source::font) + .def_readwrite("spellcheck_language", &Config::Source::spellcheck_language) + .def_readwrite("cleanup_whitespace_characters", &Config::Source::cleanup_whitespace_characters) + .def_readwrite("show_whitespace_characters", &Config::Source::show_whitespace_characters) + .def_readwrite("format_style_on_save", &Config::Source::format_style_on_save) + .def_readwrite("format_style_on_save_if_style_file_found", &Config::Source::format_style_on_save_if_style_file_found) + .def_readwrite("smart_inserts", &Config::Source::smart_inserts) + .def_readwrite("show_map", &Config::Source::show_map) + .def_readwrite("map_font_size", &Config::Source::map_font_size) + .def_readwrite("show_git_diff", &Config::Source::show_git_diff) + .def_readwrite("show_background_pattern", &Config::Source::show_background_pattern) + .def_readwrite("show_right_margin", &Config::Source::show_right_margin) + .def_readwrite("right_margin_position", &Config::Source::right_margin_position) + .def_readwrite("auto_tab_char_and_size", &Config::Source::auto_tab_char_and_size) + .def_readwrite("default_tab_char", &Config::Source::default_tab_char) + .def_readwrite("default_tab_size", &Config::Source::default_tab_size) + .def_readwrite("tab_indents_line", &Config::Source::tab_indents_line) + .def_readwrite("wrap_lines", &Config::Source::wrap_lines) + .def_readwrite("highlight_current_line", &Config::Source::highlight_current_line) + .def_readwrite("show_line_numbers", &Config::Source::show_line_numbers) + .def_readwrite("enable_multiple_cursors", &Config::Source::enable_multiple_cursors) + .def_readwrite("auto_reload_changed_files", &Config::Source::auto_reload_changed_files) + .def_readwrite("clang_format_style", &Config::Source::clang_format_style) + .def_readwrite("clang_usages_threads", &Config::Source::clang_usages_threads) + .def_readwrite("documentation_searches", &Config::Source::documentation_searches) + + ; + + py::class_(config, "Log") + .def_readwrite("libclang", &Config::Log::libclang) + .def_readwrite("language_server", &Config::Log::language_server) + + ; + py::class_(config, "Plugins") + .def_readwrite("enabled", &Config::Plugins::enabled) + .def_readwrite("path", &Config::Plugins::path) + + ; + config + .def_readwrite("menu", &Config::menu) + .def_readwrite("theme", &Config::theme) + .def_readwrite("terminal", &Config::terminal) + .def_readwrite("project", &Config::project) + .def_readwrite("source", &Config::source) + .def_readwrite("log", &Config::log) + .def_readwrite("plugins", &Config::plugins) + .def_readwrite("home_path", &Config::home_path) + .def_readwrite("home_juci_path", &Config::home_juci_path) + + ; +} diff --git a/tests/python_bindings/CMakeLists.txt b/tests/python_bindings/CMakeLists.txt index 8d2bd54..41ef3c8 100644 --- a/tests/python_bindings/CMakeLists.txt +++ b/tests/python_bindings/CMakeLists.txt @@ -16,6 +16,10 @@ add_executable(pb_compile_commands_test CompileCommands_tests/compile_commands_t target_link_libraries(pb_compile_commands_test test_suite) add_test(pb_compile_commands_test pb_compile_commands_test) +add_executable(pb_config_test Config_tests/config_test.cc $) +target_link_libraries(pb_config_test test_suite) +add_test(pb_config_test pb_config_test) + add_executable(pb_terminal_test Terminal_tests/terminal_test.cc $) target_link_libraries(pb_terminal_test test_suite) add_test(pb_terminal_test pb_terminal_test) diff --git a/tests/python_bindings/Config_tests/config_test.cc b/tests/python_bindings/Config_tests/config_test.cc new file mode 100644 index 0000000..601a2d4 --- /dev/null +++ b/tests/python_bindings/Config_tests/config_test.cc @@ -0,0 +1,14 @@ +#include "test_suite.h" +#include + +int main() { + auto &config = Config::get(); + auto suite_name = "Config_tests"; + suite test_suite(suite_name); + try { + py::module::import("config_test"); + test_suite.has_assertion = true; + } catch(const py::error_already_set &error){ + std::cout << error.what(); + } +} diff --git a/tests/python_bindings/Config_tests/config_test.py b/tests/python_bindings/Config_tests/config_test.py new file mode 100644 index 0000000..f1be75f --- /dev/null +++ b/tests/python_bindings/Config_tests/config_test.py @@ -0,0 +1,3 @@ +from Jucipp import Config + +config = Config() diff --git a/tests/stubs/config.cc b/tests/stubs/config.cc index 2d75322..52f73ea 100644 --- a/tests/stubs/config.cc +++ b/tests/stubs/config.cc @@ -2,4 +2,3 @@ Config::Config() {} void Config::load() {} -void Config::init_module(py::module &) {}