feat(python/config): added config module bindings
This commit is contained in:
@@ -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
|
||||
],
|
||||
|
||||
@@ -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')
|
||||
|
||||
55
src/python/config/bindings.cpp
Normal file
55
src/python/config/bindings.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h> // Needed for vectors, maps, sets, strings
|
||||
#include <pybind11/stl_bind.h> // Needed for binding std::vector, std::map etc if needed directly
|
||||
|
||||
#include <string>
|
||||
#include "bindings.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
// Helper function template for binding Config::get
|
||||
template <typename T>
|
||||
void def_config_get(py::module &m) {
|
||||
m.def("get",
|
||||
[](const std::string &key, T defaultValue) {
|
||||
return Config::getInstance().get<T>(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<int>(config_submodule);
|
||||
def_config_get<double>(config_submodule);
|
||||
def_config_get<std::string>(config_submodule);
|
||||
def_config_get<bool>(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("<fourdsse_bindings.config module accessing C++ Singleton>\n") + oss.str();
|
||||
});
|
||||
}
|
||||
5
src/python/config/bindings.h
Normal file
5
src/python/config/bindings.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
void register_config_bindings(pybind11::module &config_submodule);
|
||||
17
src/python/config/meson.build
Normal file
17
src/python/config/meson.build
Normal file
@@ -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,
|
||||
)
|
||||
@@ -1,2 +1,3 @@
|
||||
subdir('composition')
|
||||
subdir('const')
|
||||
subdir('const')
|
||||
subdir('config')
|
||||
Reference in New Issue
Block a user