diff --git a/build-python/meson.build b/build-python/meson.build index b7adeae..7141c6e 100644 --- a/build-python/meson.build +++ b/build-python/meson.build @@ -7,10 +7,12 @@ py_mod = py_installation.extension_module( meson.project_source_root() + '/src/python/bindings.cpp', meson.project_source_root() + '/src/python/composition/bindings.cpp', meson.project_source_root() + '/src/python/const/bindings.cpp', + meson.project_source_root() + '/src/python/config/bindings.cpp', ], dependencies : [ pybind11_dep, const_dep, + config_dep, composition_dep, species_weight_dep ], diff --git a/meson_options.txt b/meson_options.txt index cc87109..6c51e48 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,11 @@ +# Build options for the project + +# Usage: +# -Doption_name=value + +# -Dbuild_tests=true (default) build tests +# -Duser_mode=false (default) enable user mode (set mode = 0) If user mode is enabled then the optimization level is set to 3 and the build type is set to release +# -Dbuild_python=true (default) build Python bindings option('build_tests', type: 'boolean', value: true, description: 'Build tests') option('user_mode', type: 'boolean', value: false, description: 'Enable user mode (set mode = 0)') option('build_python', type: 'boolean', value: true, description: 'Build Python bindings') diff --git a/src/python/config/bindings.cpp b/src/python/config/bindings.cpp new file mode 100644 index 0000000..69e04ca --- /dev/null +++ b/src/python/config/bindings.cpp @@ -0,0 +1,55 @@ +#include +#include // Needed for vectors, maps, sets, strings +#include // Needed for binding std::vector, std::map etc if needed directly + +#include +#include "bindings.h" + +#include "config.h" + +namespace py = pybind11; + +// Helper function template for binding Config::get +template +void def_config_get(py::module &m) { + m.def("get", + [](const std::string &key, T defaultValue) { + return Config::getInstance().get(key, defaultValue); + }, + py::arg("key"), py::arg("defaultValue"), + "Get configuration value (type inferred from default)"); +} + +void register_config_bindings(pybind11::module &config_submodule) { + def_config_get(config_submodule); + def_config_get(config_submodule); + def_config_get(config_submodule); + def_config_get(config_submodule); + + config_submodule.def("loadConfig", + [](const std::string& configFilePath) { + return Config::getInstance().loadConfig(configFilePath); + }, + py::arg("configFilePath"), + "Load configuration from a YAML file."); + + config_submodule.def("has", + [](const std::string &key) { + return Config::getInstance().has(key); + }, + py::arg("key"), + "Check if a key exists in the configuration."); + + config_submodule.def("keys", + []() { + return py::cast(Config::getInstance().keys()); + }, + "Get a list of all configuration keys."); + + config_submodule.def("__repr__", + []() { + std::ostringstream oss; + oss << Config::getInstance(); // Use the existing operator<< + return std::string("\n") + oss.str(); + }); +} diff --git a/src/python/config/bindings.h b/src/python/config/bindings.h new file mode 100644 index 0000000..30fcae7 --- /dev/null +++ b/src/python/config/bindings.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void register_config_bindings(pybind11::module &config_submodule); diff --git a/src/python/config/meson.build b/src/python/config/meson.build new file mode 100644 index 0000000..cfc749c --- /dev/null +++ b/src/python/config/meson.build @@ -0,0 +1,17 @@ +# Define the library +bindings_sources = files('bindings.cpp') +bindings_headers = files('bindings.h') + +dependencies = [ + config_dep, + python3_dep, + pybind11_dep, +] + +shared_module('py_config', + bindings_sources, + include_directories: include_directories('.'), + cpp_args: ['-fvisibility=default'], + install : true, + dependencies: dependencies, +) \ No newline at end of file diff --git a/src/python/meson.build b/src/python/meson.build index be2d427..4d21619 100644 --- a/src/python/meson.build +++ b/src/python/meson.build @@ -1,2 +1,3 @@ subdir('composition') -subdir('const') \ No newline at end of file +subdir('const') +subdir('config') \ No newline at end of file