python shenanigans

This commit is contained in:
Christoph J. Scherr 2023-09-29 13:42:37 +02:00
parent 8cd7dcd77d
commit 2fb3fc298c
2 changed files with 14 additions and 93 deletions

View File

@ -13,7 +13,10 @@ keywords.workspace = true
categories.workspace = true categories.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "_libpt"
crate-type = ["cdylib"]
[dependencies] [dependencies]
libpt = { path = "../../" }
pyo3 = { workspace = true } pyo3 = { workspace = true }
libpt = { version = "0.1.7", path = "../../" }

View File

@ -1,100 +1,18 @@
use libpt::{
log::*,
};
use pyo3::prelude::*; use pyo3::prelude::*;
// FIXME: simply importing libpt causes maturin to fail,
// -> `liblibpt.so` not found
// It works without the import
use libpt;
//// PUBLIC FUNCTIONS ////////////////////////////////////////////////////////////////////////////// /// Formats the sum of two numbers as string.
/// ## Check if [`libpt`](crate) has been loaded
///
/// Always returns `true` if you can execute it.
#[pyfunction] #[pyfunction]
pub fn is_loaded() -> bool { fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
true Ok((a + b).to_string())
} }
//// PRIVATE FUNCTIONS ///////////////////////////////////////////////////////////////////////////// /// A Python module implemented in Rust.
/// ## Python module: logger
#[pymodule] #[pymodule]
fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> { fn _libpt(_py: Python, m: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "logger")?; m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
module.add_class::<Logger>()?;
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::<networking::monitoring::uptime::UptimeStatus>()?;
// 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)?;
Ok(()) Ok(())
} }