From e61aeabfbb020b86d0bc8b017a4c0ae792fe2821 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 22 Mar 2025 09:37:02 +0000 Subject: [PATCH] Integrate logging in the Python wrapper --- Cargo.lock | 18 ++++++++++++++++++ README.md | 24 +----------------------- pyo3/Cargo.toml | 1 + pyo3/README.md | 34 ++-------------------------------- pyo3/src/lib.rs | 2 ++ 5 files changed, 24 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 591e82ef..dd8f188b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,12 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "arraydeque" version = "0.5.1" @@ -623,6 +629,7 @@ dependencies = [ "libloot", "libloot-ffi-errors", "pyo3", + "pyo3-log", ] [[package]] @@ -894,6 +901,17 @@ dependencies = [ "pyo3-build-config", ] +[[package]] +name = "pyo3-log" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b78e4983ba15bc62833a0e0941d965bc03690163f1127864f1408db25063466" +dependencies = [ + "arc-swap", + "log", + "pyo3", +] + [[package]] name = "pyo3-macros" version = "0.24.0" diff --git a/README.md b/README.md index 3a0b2e7c..601b878f 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,6 @@ # libloot-rs -This is an **incomplete** and **experimental** reimplementation of [libloot](https://github.com/loot/libloot) using Rust instead of C++. - -## Current status - -Currently complete: - -- [x] Public API types and function declarations -- [x] Public API doc comments -- [x] Library versioning -- [x] Setting a logging callback -- [x] Parsing metadata from YAML -- [x] Serialising metadata to YAML -- [x] Game-related functionality -- [x] Plugin-related functionality -- [x] Archive-related functionality -- [x] Metadata-related functionality (excluding writing YAML) -- [x] Sorting functionality -- [x] Unit tests -- [x] Integration tests -- [x] C++ FFI -- [ ] Python FFI - -The complete bits should match libloot v0.25.5. +This is an **experimental** reimplementation of [libloot](https://github.com/loot/libloot) using Rust instead of C++, that should match libloot v0.25.5. ## Build diff --git a/pyo3/Cargo.toml b/pyo3/Cargo.toml index 5bb65565..fde8fe24 100644 --- a/pyo3/Cargo.toml +++ b/pyo3/Cargo.toml @@ -12,3 +12,4 @@ crate-type = ["cdylib"] libloot = { path = ".." } libloot-ffi-errors = { path = "../ffi-errors" } pyo3 = "0.24.0" +pyo3-log = "0.12.2" diff --git a/pyo3/README.md b/pyo3/README.md index cca22f10..087e5267 100644 --- a/pyo3/README.md +++ b/pyo3/README.md @@ -1,37 +1,6 @@ # libloot-pyo3 -An **incomplete** and **experimental** Python wrapper around the libloot Rust implementation, built using [PyO3](https://pyo3.rs). - -## Current coverage - -- [x] `LIBLOOT_VERSION_MAJOR` -- [x] `LIBLOOT_VERSION_MINOR` -- [x] `LIBLOOT_VERSION_PATCH` -- [x] `is_compatible()` -- [x] `libloot_revision()` -- [x] `libloot_version()` -- [ ] `set_logging_callback()` -- [ ] `set_log_level()` -- [x] `EdgeType` -- [x] `GameType` -- [ ] `LogLevel` -- [x] `Database` -- [x] `Game` -- [x] `Plugin` -- [x] `Vertex` -- [x] `File` -- [x] `Filename` -- [x] `Group` -- [x] `Location` -- [x] `Message` -- [x] `MessageContent` -- [x] `PluginCleaningData` -- [x] `PluginMetadata` -- [x] `Tag` -- [x] `MessageType` -- [x] `TagSuggestion` -- [x] `select_message_content()` -- [x] Error types +An **experimental** Python wrapper around the libloot Rust implementation, built using [PyO3](https://pyo3.rs). ## Build @@ -64,3 +33,4 @@ py - The API provides the custom `CyclicInteractionError`, `UndefinedGroupError`, `EspluginError` exception types. - All other errors are raised as `ValueError` exceptions. - There's no equivalent to the C++ interface's `FileAccessError` or `ConditionSyntaxError` classes or the libloadorder and loot-condition-interpreter system error categories. +- The `LogLevel` enum and `set_logging_callback()` and `set_log_level()` functions are not exposed because the logging is integrated with Python's `logging` module instead. diff --git a/pyo3/src/lib.rs b/pyo3/src/lib.rs index 8a871ee5..bfe1d40d 100644 --- a/pyo3/src/lib.rs +++ b/pyo3/src/lib.rs @@ -35,6 +35,8 @@ create_exception!(loot, EspluginError, PyException); /// A Python module implemented in Rust. #[pymodule(name = "loot")] fn libloot_pyo3(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { + pyo3_log::init(); + m.add("LIBLOOT_VERSION_MAJOR", libloot::LIBLOOT_VERSION_MAJOR)?; m.add("LIBLOOT_VERSION_MINOR", libloot::LIBLOOT_VERSION_MINOR)?; m.add("LIBLOOT_VERSION_PATCH", libloot::LIBLOOT_VERSION_PATCH)?;