From 2fb3fc298c866ac4ece685643db73d601957105a Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Fri, 29 Sep 2023 13:42:37 +0200 Subject: [PATCH] python shenanigans --- members/pt-py/Cargo.toml | 5 +- members/pt-py/src/lib.rs | 102 ++++----------------------------------- 2 files changed, 14 insertions(+), 93 deletions(-) diff --git a/members/pt-py/Cargo.toml b/members/pt-py/Cargo.toml index 1f9a8dd..a1c006b 100644 --- a/members/pt-py/Cargo.toml +++ b/members/pt-py/Cargo.toml @@ -13,7 +13,10 @@ keywords.workspace = true categories.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "_libpt" +crate-type = ["cdylib"] [dependencies] -libpt = { path = "../../" } pyo3 = { workspace = true } +libpt = { version = "0.1.7", path = "../../" } diff --git a/members/pt-py/src/lib.rs b/members/pt-py/src/lib.rs index 13baee9..b7cbf07 100644 --- a/members/pt-py/src/lib.rs +++ b/members/pt-py/src/lib.rs @@ -1,100 +1,18 @@ -use libpt::{ - log::*, -}; - use pyo3::prelude::*; +// FIXME: simply importing libpt causes maturin to fail, +// -> `liblibpt.so` not found +// It works without the import +use libpt; -//// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// -/// ## Check if [`libpt`](crate) has been loaded -/// -/// Always returns `true` if you can execute it. +/// Formats the sum of two numbers as string. #[pyfunction] -pub fn is_loaded() -> bool { - true +fn sum_as_string(a: usize, b: usize) -> PyResult { + Ok((a + b).to_string()) } -//// PRIVATE FUNCTIONS ///////////////////////////////////////////////////////////////////////////// -/// ## Python module: logger +/// A Python module implemented in Rust. #[pymodule] -fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "logger")?; - module.add_class::()?; - - parent.add_submodule(module)?; - Ok(()) -} -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: common -// #[pymodule] -// fn py_common(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "common")?; -// py_common_printing(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: common.printing -// #[pymodule] -// fn py_common_printing(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "printing")?; -// module.add_function(wrap_pyfunction!(common::printing::divider, module)?)?; -// module.add_function(wrap_pyfunction!(common::printing::print_divider, module)?)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking -// #[pymodule] -// fn py_networking(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "networking")?; -// py_networking_monitoring(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking.monitoring -// #[pymodule] -// fn py_networking_monitoring(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "monitoring")?; -// py_networking_monitoring_uptime(py, module)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } -// -// //////////////////////////////////////////////////////////////////////////////////////////////////// -// /// ## Python module: networking.monitoring.uptime -// #[pymodule] -// fn py_networking_monitoring_uptime(py: Python, parent: &PyModule) -> PyResult<()> { -// let module = PyModule::new(py, "uptime")?; -// module.add_class::()?; -// module.add_function(wrap_pyfunction!( -// networking::monitoring::uptime::py_continuous_uptime_monitor, -// module -// )?)?; -// -// parent.add_submodule(module)?; -// Ok(()) -// } - -//////////////////////////////////////////////////////////////////////////////////////////////////// -/// ## Python module: root -/// -/// This function is the entry point of [`PyO3`](pyo3). This is where the main module is built. -#[pymodule] -fn _libpt(py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(is_loaded, m)?)?; - - // load sub modules - // py_common(py, m)?; - py_logger(py, m)?; - // py_networking(py, m)?; +fn _libpt(_py: Python, m: &PyModule) -> PyResult<()> { + m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; Ok(()) }