structure stuff

This commit is contained in:
Christoph J. Scherr 2023-09-20 18:15:53 +02:00
parent ebac3201cd
commit 12ac4ebb38
19 changed files with 292 additions and 199 deletions

View File

@ -1,7 +1,7 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = [ members = [
"members/pt", ".",
"members/pt-core", "members/pt-core",
"members/pt-bintols", "members/pt-bintols",
"members/pt-math", "members/pt-math",
@ -12,7 +12,7 @@ members = [
"members/pt-hedu", "members/pt-hedu",
] ]
default-members = [ default-members = [
"members/pt", ".",
"members/pt-bin", "members/pt-bin",
"members/pt-core", "members/pt-core",
"members/pt-py", "members/pt-py",
@ -34,3 +34,38 @@ categories = ["command-line-utilities", "development-tools", "development-tools:
[workspace.dependencies] [workspace.dependencies]
pyo3 = "0.19" pyo3 = "0.19"
[package]
name = "pt"
publish.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
[features]
default = ["core", "log"]
core = []
math = []
log = []
bintols = []
net = []
ccc = ["math"]
hedu = ["bintols"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pt-bintols = { version = "0.1.0", path = "members/pt-bintols" }
pt-core = { version = "0.1.0", path = "members/pt-core" }
pt-hedu = { version = "0.1.0", path = "members/pt-hedu" }
pt-log = { version = "0.1.0", path = "members/pt-log" }
pt-math = { version = "0.1.0", path = "members/pt-math" }
pt-net = { version = "0.1.0", path = "members/pt-net" }
pt-ccc = { version = "0.1.0", path = "members/pt-ccc" }

View File

@ -1,8 +1,17 @@
[package] [package]
autobins = true autobins = true
name = "pt-bin" name = "pt-bin"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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

View File

@ -1,10 +1,20 @@
[package] [package]
name = "pt-bintols" name = "pt-bintols"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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
[dependencies] [dependencies]
num-traits = "0.2.16"
pt-core = { version = "0.1.0", path = "../pt-core" } pt-core = { version = "0.1.0", path = "../pt-core" }
pt-log = { version = "0.1.0", path = "../pt-log" } pt-log = { version = "0.1.0", path = "../pt-log" }

View File

@ -1,8 +1,22 @@
[package] [package]
name = "pt-ccc" name = "pt-ccc"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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
[dependencies] [dependencies]
num = "0.4.1"
num-traits = "0.2.16"
pt-core = { version = "0.1.7", path = "../pt-core" }
pt-log = { version = "0.1.7", path = "../pt-log" }
pt-math = { version = "0.1.7", path = "../pt-math" }

View File

@ -15,6 +15,11 @@
use std::fmt::Display; use std::fmt::Display;
pub use num_traits::PrimInt; pub use num_traits::PrimInt;
#[allow(unused_imports)] // we possibly want to use all log levels
use pt_log::*;
#[allow(unused_imports)] // import more complex math stuff from there
use pt_math;
//// TYPES ///////////////////////////////////////////////////////////////////////////////////////// //// TYPES /////////////////////////////////////////////////////////////////////////////////////////
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,3 +1,83 @@
fn main() { //! # Calculate expressions
println!("Hello, world!"); //!
//! Calculate Calculations with your Calculator (`ccc`)
//!
//! This modules aim is to take a term of any kind ([String]) and calculate it's value, be it
//! variable based or a concrete numerical value. It implements different operators and
//! (mathematical) functions.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub mod base;
pub use base::{Error, Result, Value};
pub mod term;
pub use term::*;
#[allow(unused_imports)] // we possibly want to use all log levels
use pt_log::*;
#[allow(unused_imports)] // import more complex math stuff from there
use pt_math;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
/// ## A Calculator struct
///
/// This struct does not do anything at the moment, but aims to be the target for high level
/// control. Instead of using the [`Calculator`], you could just use the [`Term`] struct for
/// lower level control.
#[derive(Debug)]
pub struct Calculator;
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
impl Calculator {
/// Do a single calculation without doing anything else
pub fn oneshot(t: String) -> Result<Value> {
trace!(orig=t, "parsing original string to Term");
let t = Term::new(t)?;
trace!("term has been parsed, starting Calculation");
debug!("parsed term: {t:#?}");
Self::calc(t)
} }
/// ## Calculate a [`Term`]
///
/// This method makes use of the
/// [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) to
/// Calculate the final value of any term.
///
/// This method only processes a single term at a time, without caching.
pub fn calc(mut t: Term) -> Result<Value> {
trace!("Calculating term {t:?}");
t.prepare()?;
t.process()?;
if t.result.is_none() {
let reason = format!("Term was processed but no result was assigned.");
// FIXME: unfitting error type
return Err(Error::SyntaxError(reason))
}
return t.result.unwrap()
}
}
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -21,7 +21,10 @@ use std::collections::VecDeque;
//// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// //// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub use super::{Error, Result, Value, base::{self, *}}; pub use super::{Error, Result, Value, base::{self, *}};
use crate::logger::*; #[allow(unused_imports)] // we possibly want to use all log levels
use pt_log::*;
#[allow(unused_imports)] // import more complex math stuff from there
use pt_math;
//// TYPES ///////////////////////////////////////////////////////////////////////////////////////// //// TYPES /////////////////////////////////////////////////////////////////////////////////////////

View File

@ -23,8 +23,6 @@ pub mod macros;
pub mod printing; pub mod printing;
//// CONSTANTS ///////////////////////////////////////////////////////////////////////////////////// //// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
pub const EXIT_SUCCESS: i32 = 0;
pub const EXIT_FAILURE_USAGE: i32 = 1;
//// STATICS /////////////////////////////////////////////////////////////////////////////////////// //// STATICS ///////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,16 @@
[package] [package]
name = "pt-hedu" name = "pt-hedu"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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

View File

@ -107,7 +107,7 @@ impl Logger {
warn!("trying to reinitialize the logger, ignoring"); warn!("trying to reinitialize the logger, ignoring");
return Err(Error::Usage(format!("logging is already initialized"))); return Err(Error::Usage(format!("logging is already initialized")));
} else { } else {
let filter = tracing_subscriber::filter::FilterFn::new(|metadata| { let filter = tracing_subscriber::filter::FilterFn::new(|_metadata| {
// let mut filter = false; // let mut filter = false;
// //
// // if it's this lib, continue // // if it's this lib, continue

View File

@ -1,7 +1,16 @@
[package] [package]
name = "pt-math" name = "pt-math"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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

View File

@ -1,81 +0,0 @@
//! # Calculate expressions
//!
//! Calculate Calculations with your Calculator (`ccc`)
//!
//! This modules aim is to take a term of any kind ([String]) and calculate it's value, be it
//! variable based or a concrete numerical value. It implements different operators and
//! (mathematical) functions.
//// ATTRIBUTES ////////////////////////////////////////////////////////////////////////////////////
// we want docs
#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]
// we want Debug everywhere.
#![warn(missing_debug_implementations)]
// enable clippy's extra lints, the pedantic version
#![warn(clippy::pedantic)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub mod base;
pub use base::{Error, Result, Value};
pub mod term;
pub use term::*;
#[allow(unused_imports)] // we possibly want to use all log levels
use crate::logger::{trace, debug, info, warn, error};
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////
//// CONSTANTS /////////////////////////////////////////////////////////////////////////////////////
//// STATICS ///////////////////////////////////////////////////////////////////////////////////////
//// MACROS ////////////////////////////////////////////////////////////////////////////////////////
//// ENUMS /////////////////////////////////////////////////////////////////////////////////////////
//// STRUCTS ///////////////////////////////////////////////////////////////////////////////////////
/// ## A Calculator struct
///
/// This struct does not do anything at the moment, but aims to be the target for high level
/// control. Instead of using the [`Calculator`], you could just use the [`Term`] struct for
/// lower level control.
#[derive(Debug)]
pub struct Calculator;
//// IMPLEMENTATION ////////////////////////////////////////////////////////////////////////////////
impl Calculator {
/// Do a single calculation without doing anything else
pub fn oneshot(t: String) -> Result<Value> {
trace!(orig=t, "parsing original string to Term");
let t = Term::new(t)?;
trace!("term has been parsed, starting Calculation");
debug!("parsed term: {t:#?}");
Self::calc(t)
}
/// ## Calculate a [`Term`]
///
/// This method makes use of the
/// [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) to
/// Calculate the final value of any term.
///
/// This method only processes a single term at a time, without caching.
pub fn calc(mut t: Term) -> Result<Value> {
trace!("Calculating term {t:?}");
t.prepare()?;
t.process()?;
if t.result.is_none() {
let reason = format!("Term was processed but no result was assigned.");
// FIXME: unfitting error type
return Err(Error::SyntaxError(reason))
}
return t.result.unwrap()
}
}
//// PUBLIC FUNCTIONS //////////////////////////////////////////////////////////////////////////////
//// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -18,7 +18,6 @@
#![warn(clippy::pedantic)] #![warn(clippy::pedantic)]
//// IMPORTS /////////////////////////////////////////////////////////////////////////////////////// //// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub mod calculator;
//// TYPES ///////////////////////////////////////////////////////////////////////////////////////// //// TYPES /////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,16 @@
[package] [package]
name = "pt-net" name = "pt-net"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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

View File

@ -1,10 +1,19 @@
[package] [package]
name = "pt-py" name = "pt-py"
version = "0.1.0" publish.workspace = true
edition = "2021" version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.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
[dependencies] [dependencies]
pt = { version = "0.1.0", path = "../pt" } pt = { path = "../../" }
pyo3 = { workspace = true } pyo3 = { workspace = true }

View File

@ -1,4 +1,6 @@
use pt::*; use pt::{
log::*,
};
use pyo3::prelude::*; use pyo3::prelude::*;
@ -21,66 +23,66 @@ fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> {
parent.add_submodule(module)?; parent.add_submodule(module)?;
Ok(()) Ok(())
} }
//
//////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: common // /// ## Python module: common
#[pymodule] // #[pymodule]
fn py_common(py: Python, parent: &PyModule) -> PyResult<()> { // fn py_common(py: Python, parent: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "common")?; // let module = PyModule::new(py, "common")?;
py_common_printing(py, module)?; // py_common_printing(py, module)?;
//
parent.add_submodule(module)?; // parent.add_submodule(module)?;
Ok(()) // Ok(())
} // }
//
//////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: common.printing // /// ## Python module: common.printing
#[pymodule] // #[pymodule]
fn py_common_printing(py: Python, parent: &PyModule) -> PyResult<()> { // fn py_common_printing(py: Python, parent: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "printing")?; // let module = PyModule::new(py, "printing")?;
module.add_function(wrap_pyfunction!(common::printing::divider, module)?)?; // module.add_function(wrap_pyfunction!(common::printing::divider, module)?)?;
module.add_function(wrap_pyfunction!(common::printing::print_divider, module)?)?; // module.add_function(wrap_pyfunction!(common::printing::print_divider, module)?)?;
//
parent.add_submodule(module)?; // parent.add_submodule(module)?;
Ok(()) // Ok(())
} // }
//
//////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: networking // /// ## Python module: networking
#[pymodule] // #[pymodule]
fn py_networking(py: Python, parent: &PyModule) -> PyResult<()> { // fn py_networking(py: Python, parent: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "networking")?; // let module = PyModule::new(py, "networking")?;
py_networking_monitoring(py, module)?; // py_networking_monitoring(py, module)?;
//
parent.add_submodule(module)?; // parent.add_submodule(module)?;
Ok(()) // Ok(())
} // }
//
//////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: networking.monitoring // /// ## Python module: networking.monitoring
#[pymodule] // #[pymodule]
fn py_networking_monitoring(py: Python, parent: &PyModule) -> PyResult<()> { // fn py_networking_monitoring(py: Python, parent: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "monitoring")?; // let module = PyModule::new(py, "monitoring")?;
py_networking_monitoring_uptime(py, module)?; // py_networking_monitoring_uptime(py, module)?;
//
parent.add_submodule(module)?; // parent.add_submodule(module)?;
Ok(()) // Ok(())
} // }
//
//////////////////////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: networking.monitoring.uptime // /// ## Python module: networking.monitoring.uptime
#[pymodule] // #[pymodule]
fn py_networking_monitoring_uptime(py: Python, parent: &PyModule) -> PyResult<()> { // fn py_networking_monitoring_uptime(py: Python, parent: &PyModule) -> PyResult<()> {
let module = PyModule::new(py, "uptime")?; // let module = PyModule::new(py, "uptime")?;
module.add_class::<networking::monitoring::uptime::UptimeStatus>()?; // module.add_class::<networking::monitoring::uptime::UptimeStatus>()?;
module.add_function(wrap_pyfunction!( // module.add_function(wrap_pyfunction!(
networking::monitoring::uptime::py_continuous_uptime_monitor, // networking::monitoring::uptime::py_continuous_uptime_monitor,
module // module
)?)?; // )?)?;
//
parent.add_submodule(module)?; // parent.add_submodule(module)?;
Ok(()) // Ok(())
} // }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
/// ## Python module: root /// ## Python module: root
@ -91,8 +93,8 @@ fn _libpt(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(is_loaded, m)?)?; m.add_function(wrap_pyfunction!(is_loaded, m)?)?;
// load sub modules // load sub modules
py_common(py, m)?; // py_common(py, m)?;
py_logger(py, m)?; py_logger(py, m)?;
py_networking(py, m)?; // py_networking(py, m)?;
Ok(()) Ok(())
} }

View File

@ -1,24 +0,0 @@
[package]
name = "pt"
publish.workspace = true
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
pt-bintols = { version = "0.1.0", path = "../pt-bintols" }
pt-core = { version = "0.1.0", path = "../pt-core" }
pt-hedu = { version = "0.1.0", path = "../pt-hedu" }
pt-log = { version = "0.1.0", path = "../pt-log" }
pt-math = { version = "0.1.0", path = "../pt-math" }
pt-net = { version = "0.1.0", path = "../pt-net" }
pt-ccc = { version = "0.1.0", path = "../pt-ccc" }

View File

@ -1,7 +0,0 @@
pub use pt_core;
pub use pt_bintols;
pub use pt_hedu;
pub use pt_log;
pub use pt_math;
pub use pt_net;
pub use pt_ccc;

14
src/lib.rs Normal file
View File

@ -0,0 +1,14 @@
#[cfg(feature = "core")]
pub use pt_core as core;
#[cfg(feature = "bintols")]
pub use pt_bintols as bintols;
#[cfg(feature = "hedu")]
pub use pt_hedu as hedu;
#[cfg(feature = "log")]
pub use pt_log as log;
#[cfg(feature = "math")]
pub use pt_math as math;
#[cfg(feature = "net")]
pub use pt_net as net;
#[cfg(feature = "ccc")]
pub use pt_ccc as ccc;