From 087e6dad8c1d50ab768d2e25ded77018eb08e5b6 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Tue, 9 Jul 2024 19:41:34 +0200 Subject: [PATCH] refactor(py)!: remove libpt-py #87 --- Cargo.toml | 15 +---- members/libpt-py/.gitignore | 72 --------------------- members/libpt-py/Cargo.toml | 31 --------- members/libpt-py/pyproject.toml | 16 ----- members/libpt-py/src/bintols/mod.rs | 76 ---------------------- members/libpt-py/src/core/mod.rs | 11 ---- members/libpt-py/src/core/printing.rs | 24 ------- members/libpt-py/src/lib.rs | 30 --------- members/libpt-py/src/log/mod.rs | 91 --------------------------- members/libpt-py/src/net/mod.rs | 0 10 files changed, 2 insertions(+), 364 deletions(-) delete mode 100644 members/libpt-py/.gitignore delete mode 100644 members/libpt-py/Cargo.toml delete mode 100644 members/libpt-py/pyproject.toml delete mode 100644 members/libpt-py/src/bintols/mod.rs delete mode 100644 members/libpt-py/src/core/mod.rs delete mode 100644 members/libpt-py/src/core/printing.rs delete mode 100644 members/libpt-py/src/lib.rs delete mode 100644 members/libpt-py/src/log/mod.rs delete mode 100644 members/libpt-py/src/net/mod.rs diff --git a/Cargo.toml b/Cargo.toml index c0277fa..1b9d809 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,6 @@ [workspace] resolver = "2" -members = [ - ".", - "members/libpt-core", - "members/libpt-log", - "members/libpt-py", - "members/libpt-cli", -] +members = [".", "members/libpt-core", "members/libpt-log", "members/libpt-cli"] default-members = [".", "members/libpt-core"] [workspace.package] @@ -20,11 +14,7 @@ readme = "README.md" homepage = "https://git.cscherr.de/PlexSheep/pt" repository = "https://git.cscherr.de/PlexSheep/pt" keywords = ["library"] -categories = [ - "command-line-utilities", - "development-tools", - "development-tools::ffi", -] +categories = ["command-line-utilities", "development-tools"] [workspace.dependencies] anyhow = "1.0.79" @@ -55,7 +45,6 @@ full = ["default", "core", "log", "bintols"] log = ["dep:libpt-log"] bintols = ["dep:libpt-bintols", "log"] cli = ["dep:libpt-cli", "core", "log"] -# py = ["dep:libpt-py"] [lib] name = "libpt" diff --git a/members/libpt-py/.gitignore b/members/libpt-py/.gitignore deleted file mode 100644 index c8f0442..0000000 --- a/members/libpt-py/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -/target - -# Byte-compiled / optimized / DLL files -__pycache__/ -.pytest_cache/ -*.py[cod] - -# C extensions -*.so - -# Distribution / packaging -.Python -.venv/ -env/ -bin/ -build/ -develop-eggs/ -dist/ -eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -include/ -man/ -venv/ -*.egg-info/ -.installed.cfg -*.egg - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt -pip-selfcheck.json - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.cache -nosetests.xml -coverage.xml - -# Translations -*.mo - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# Rope -.ropeproject - -# Django stuff: -*.log -*.pot - -.DS_Store - -# Sphinx documentation -docs/_build/ - -# PyCharm -.idea/ - -# VSCode -.vscode/ - -# Pyenv -.python-version diff --git a/members/libpt-py/Cargo.toml b/members/libpt-py/Cargo.toml deleted file mode 100644 index 8be932e..0000000 --- a/members/libpt-py/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "libpt-py" -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 - -[package.metadata.maturin] -name = "libpt" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type = ["cdylib", "rlib"] - -[dependencies] -libpt = { version = "0.5.0"} -pyo3 = { version = "0.19.0", features = ["full"] } -anyhow.workspace = true - -[features] -default = ["log", "core", "full"] -core = [] -full = ["default", "core", "log", "bintols"] -log = ["libpt/log"] -bintols = ["libpt/bintols", "log"] diff --git a/members/libpt-py/pyproject.toml b/members/libpt-py/pyproject.toml deleted file mode 100644 index 0b1145a..0000000 --- a/members/libpt-py/pyproject.toml +++ /dev/null @@ -1,16 +0,0 @@ -[build-system] -requires = ["maturin>=1.4,<2.0"] -build-backend = "maturin" - -[project] -name = "libpt" -requires-python = ">=3.8" -classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", -] -dynamic = ["version"] - -[tool.maturin] -features = ["pyo3/extension-module"] diff --git a/members/libpt-py/src/bintols/mod.rs b/members/libpt-py/src/bintols/mod.rs deleted file mode 100644 index 72f19be..0000000 --- a/members/libpt-py/src/bintols/mod.rs +++ /dev/null @@ -1,76 +0,0 @@ -use pyo3::prelude::*; - -use libpt::bintols as origin; - -mod split { - use libpt::bintols::split as origin; - use pyo3::prelude::*; - - #[pyfunction] - pub fn split_int(data: u128) -> Vec { - origin::unsigned_to_vec(data) - } - - /// implement a python module in Rust - pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "split")?; - - module.add_function(wrap_pyfunction!(split_int, module)?)?; - - parent.add_submodule(module)?; - Ok(()) - } -} - -mod display { - use libpt::bintols::display as origin; - use pyo3::prelude::*; - - #[pyfunction] - pub fn bytes_to_bin(data: &[u8]) -> String { - origin::bytes_to_bin(data) - } - - #[pyfunction] - pub fn byte_bit_display(data: usize) -> String { - origin::byte_bit_display(data) - } - - #[pyfunction] - pub fn humanbytes(total: u128) -> String { - origin::humanbytes(total) - } - - /// implement a python module in Rust - pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "display")?; - - module.add_function(wrap_pyfunction!(bytes_to_bin, module)?)?; - module.add_function(wrap_pyfunction!(byte_bit_display, module)?)?; - module.add_function(wrap_pyfunction!(humanbytes, module)?)?; - - parent.add_submodule(module)?; - Ok(()) - } -} - -/// implement a python module in Rust -pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "bintols")?; - - // binary constants - module.add("KIBI", origin::KIBI)?; - module.add("MEBI", origin::MEBI)?; - module.add("GIBI", origin::GIBI)?; - module.add("TEBI", origin::TEBI)?; - module.add("PEBI", origin::PEBI)?; - module.add("EXBI", origin::EXBI)?; - module.add("ZEBI", origin::ZEBI)?; - module.add("YOBI", origin::YOBI)?; - - display::submodule(py, module)?; - split::submodule(py, module)?; - - parent.add_submodule(module)?; - Ok(()) -} diff --git a/members/libpt-py/src/core/mod.rs b/members/libpt-py/src/core/mod.rs deleted file mode 100644 index 901d86f..0000000 --- a/members/libpt-py/src/core/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -use pyo3::prelude::*; - -mod printing; - -/// implement a python module in Rust -pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "core")?; - printing::submodule(py, module)?; - parent.add_submodule(module)?; - Ok(()) -} diff --git a/members/libpt-py/src/core/printing.rs b/members/libpt-py/src/core/printing.rs deleted file mode 100644 index 146451c..0000000 --- a/members/libpt-py/src/core/printing.rs +++ /dev/null @@ -1,24 +0,0 @@ -use pyo3::prelude::*; - -use libpt::core::printing as origin; - -/// Quickly get a one line visual divider -#[pyfunction] -pub fn divider() -> String { - origin::divider() -} - -/// Quickly print a one line visual divider -#[pyfunction] -pub fn print_divider() { - origin::print_divider() -} - -/// implement a python module in Rust -pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "printing")?; - module.add_function(wrap_pyfunction!(divider, module)?)?; - module.add_function(wrap_pyfunction!(print_divider, module)?)?; - parent.add_submodule(module)?; - Ok(()) -} diff --git a/members/libpt-py/src/lib.rs b/members/libpt-py/src/lib.rs deleted file mode 100644 index 2d648a1..0000000 --- a/members/libpt-py/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Python bindings for [`libpt`] - -#[cfg(feature = "bintols")] -mod bintols; -#[cfg(feature = "core")] -mod core; -#[cfg(feature = "log")] -mod log; - -use pyo3::prelude::*; - -/// return the version of libpt -#[pyfunction] -fn version() -> String { - env!("CARGO_PKG_VERSION").to_string() -} - -/// implement a python module in Rust -#[pymodule] -#[pyo3(name = "libpt")] -fn libpt_py(py: Python, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(version, m)?)?; - #[cfg(feature = "core")] - core::submodule(py, m)?; - #[cfg(feature = "log")] - log::submodule(py, m)?; - #[cfg(feature = "bintols")] - bintols::submodule(py, m)?; - Ok(()) -} diff --git a/members/libpt-py/src/log/mod.rs b/members/libpt-py/src/log/mod.rs deleted file mode 100644 index 6cc817f..0000000 --- a/members/libpt-py/src/log/mod.rs +++ /dev/null @@ -1,91 +0,0 @@ -use std::path::PathBuf; - -use pyo3::prelude::*; - -use libpt::log as origin; - -#[derive(Clone)] -#[pyclass] -pub enum Level { - Error, - Warn, - Info, - Debug, - Trace, -} - -impl From for origin::Level { - fn from(value: Level) -> Self { - match value { - Level::Error => origin::Level::ERROR, - Level::Warn => origin::Level::WARN, - Level::Info => origin::Level::INFO, - Level::Debug => origin::Level::DEBUG, - Level::Trace => origin::Level::TRACE, - } - } -} - -#[pyclass] -pub struct Logger { - inner: origin::Logger, -} - -impl From for Logger { - fn from(inner: origin::Logger) -> Self { - Self { inner } - } -} - -#[pymethods] -impl Logger { - #[new] - pub fn build( - log_dir: Option, - max_level: Option, - uptime: Option, - ) -> anyhow::Result { - // concert our wrapper type - let max_level = max_level.map(origin::Level::from); - let mut builder = origin::Logger::builder(); - if log_dir.is_some() { - builder = builder.log_dir(log_dir.unwrap()); - } - if max_level.is_some() { - builder = builder.max_level(max_level.unwrap()); - } - if uptime.is_some() { - builder = builder.uptime(uptime.unwrap()); - } - Ok(builder.build()?.into()) - } - - /// ## logging at [`Level::ERROR`] - pub fn error(&self, printable: String) { - self.inner.error(printable) - } - /// ## logging at [`Level::WARN`] - pub fn warn(&self, printable: String) { - self.inner.warn(printable) - } - /// ## logging at [`Level::INFO`] - pub fn info(&self, printable: String) { - self.inner.info(printable) - } - /// ## logging at [`Level::DEBUG`] - pub fn debug(&self, printable: String) { - self.inner.debug(printable) - } - /// ## logging at [`Level::StringRACE`] - pub fn trace(&self, printable: String) { - self.inner.trace(printable) - } -} - -/// implement a python module in Rust -pub fn submodule(py: Python, parent: &PyModule) -> PyResult<()> { - let module = PyModule::new(py, "log")?; - module.add_class::()?; - parent.add_submodule(module)?; - Ok(()) -} diff --git a/members/libpt-py/src/net/mod.rs b/members/libpt-py/src/net/mod.rs deleted file mode 100644 index e69de29..0000000