refactor(py)!: remove libpt-py #87
cargo devel CI / cargo CI (push) Failing after 1m40s Details

This commit is contained in:
Christoph J. Scherr 2024-07-09 19:41:34 +02:00
parent 8226d74fb9
commit 087e6dad8c
10 changed files with 2 additions and 364 deletions

View File

@ -1,12 +1,6 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = [ members = [".", "members/libpt-core", "members/libpt-log", "members/libpt-cli"]
".",
"members/libpt-core",
"members/libpt-log",
"members/libpt-py",
"members/libpt-cli",
]
default-members = [".", "members/libpt-core"] default-members = [".", "members/libpt-core"]
[workspace.package] [workspace.package]
@ -20,11 +14,7 @@ readme = "README.md"
homepage = "https://git.cscherr.de/PlexSheep/pt" homepage = "https://git.cscherr.de/PlexSheep/pt"
repository = "https://git.cscherr.de/PlexSheep/pt" repository = "https://git.cscherr.de/PlexSheep/pt"
keywords = ["library"] keywords = ["library"]
categories = [ categories = ["command-line-utilities", "development-tools"]
"command-line-utilities",
"development-tools",
"development-tools::ffi",
]
[workspace.dependencies] [workspace.dependencies]
anyhow = "1.0.79" anyhow = "1.0.79"
@ -55,7 +45,6 @@ full = ["default", "core", "log", "bintols"]
log = ["dep:libpt-log"] log = ["dep:libpt-log"]
bintols = ["dep:libpt-bintols", "log"] bintols = ["dep:libpt-bintols", "log"]
cli = ["dep:libpt-cli", "core", "log"] cli = ["dep:libpt-cli", "core", "log"]
# py = ["dep:libpt-py"]
[lib] [lib]
name = "libpt" name = "libpt"

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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<u8> {
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(())
}

View File

@ -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(())
}

View File

@ -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(())
}

View File

@ -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(())
}

View File

@ -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<Level> 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<origin::Logger> for Logger {
fn from(inner: origin::Logger) -> Self {
Self { inner }
}
}
#[pymethods]
impl Logger {
#[new]
pub fn build(
log_dir: Option<PathBuf>,
max_level: Option<Level>,
uptime: Option<bool>,
) -> anyhow::Result<Self> {
// 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::<Logger>()?;
parent.add_submodule(module)?;
Ok(())
}