use neopdf::converter::{combine_lhapdf_npdfs, convert_lhapdf};
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
#[pymodule]
pub fn converter(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(py_convert_lhapdf, m)?)?;
m.add_function(wrap_pyfunction!(py_combine_lhapdf_npdfs, m)?)?;
Ok(())
}
#[pyfunction(name = "convert_lhapdf")]
pub fn py_convert_lhapdf(pdf_name: &str, output_path: &str) -> PyResult<()> {
convert_lhapdf(pdf_name, output_path)
.map_err(|e| PyRuntimeError::new_err(format!("Conversion failed: {e}")))
}
#[pyfunction(name = "combine_lhapdf_npdfs")]
#[allow(clippy::needless_pass_by_value)]
pub fn py_combine_lhapdf_npdfs(pdf_names: Vec<String>, output_path: &str) -> PyResult<()> {
let pdf_names: Vec<&str> = pdf_names.iter().map(std::string::String::as_str).collect();
combine_lhapdf_npdfs(&pdf_names, output_path)
.map_err(|e| PyRuntimeError::new_err(format!("Combine failed: {e}")))
}
pub fn register(parent_module: &Bound<'_, PyModule>) -> PyResult<()> {
let m = PyModule::new(parent_module.py(), "converter")?;
m.setattr(
pyo3::intern!(m.py(), "__doc__"),
"PDF set conversion utilities.",
)?;
pyo3::py_run!(
parent_module.py(),
m,
"import sys; sys.modules['neopdf.converter'] = m"
);
m.add_function(wrap_pyfunction!(py_convert_lhapdf, &m)?)?;
m.add_function(wrap_pyfunction!(py_combine_lhapdf_npdfs, &m)?)?;
parent_module.add_submodule(&m)
}