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]
resolver = "2"
members = [
"members/pt",
".",
"members/pt-core",
"members/pt-bintols",
"members/pt-math",
@ -12,7 +12,7 @@ members = [
"members/pt-hedu",
]
default-members = [
"members/pt",
".",
"members/pt-bin",
"members/pt-core",
"members/pt-py",
@ -34,3 +34,38 @@ categories = ["command-line-utilities", "development-tools", "development-tools:
[workspace.dependencies]
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]
autobins = true
name = "pt-bin"
version = "0.1.0"
edition = "2021"
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

View File

@ -1,10 +1,20 @@
[package]
name = "pt-bintols"
version = "0.1.0"
edition = "2021"
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]
num-traits = "0.2.16"
pt-core = { version = "0.1.0", path = "../pt-core" }
pt-log = { version = "0.1.0", path = "../pt-log" }

View File

@ -1,8 +1,22 @@
[package]
name = "pt-ccc"
version = "0.1.0"
edition = "2021"
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]
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;
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 /////////////////////////////////////////////////////////////////////////////////////////
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,3 +1,83 @@
fn main() {
println!("Hello, world!");
//! # 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 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 ///////////////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////////////////

View File

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

View File

@ -1,7 +1,16 @@
[package]
name = "pt-hedu"
version = "0.1.0"
edition = "2021"
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

View File

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

View File

@ -1,7 +1,16 @@
[package]
name = "pt-math"
version = "0.1.0"
edition = "2021"
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

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)]
//// IMPORTS ///////////////////////////////////////////////////////////////////////////////////////
pub mod calculator;
//// TYPES /////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,16 @@
[package]
name = "pt-net"
version = "0.1.0"
edition = "2021"
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

View File

@ -1,10 +1,19 @@
[package]
name = "pt-py"
version = "0.1.0"
edition = "2021"
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 = { version = "0.1.0", path = "../pt" }
pt = { path = "../../" }
pyo3 = { workspace = true }

View File

@ -1,4 +1,6 @@
use pt::*;
use pt::{
log::*,
};
use pyo3::prelude::*;
@ -21,66 +23,66 @@ fn py_logger(py: Python, parent: &PyModule) -> PyResult<()> {
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: 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
@ -91,8 +93,8 @@ fn _libpt(py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(is_loaded, m)?)?;
// load sub modules
py_common(py, m)?;
// py_common(py, m)?;
py_logger(py, m)?;
py_networking(py, m)?;
// py_networking(py, m)?;
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;