Make jemalloc, clap and pyo3 optional dependencies (#116)

This commit is contained in:
msrd0
2023-04-21 14:17:35 +02:00
committed by GitHub
parent f4d96c73a8
commit 6a065de6fc
4 changed files with 37 additions and 9 deletions

View File

@@ -8,6 +8,10 @@ name = "synapse_compress_state"
version = "0.1.0"
edition = "2018"
[[bin]]
name = "synapse_compress_state"
required-features = ["clap"]
[dependencies]
indicatif = "0.17.0"
openssl = "0.10.48"
@@ -18,7 +22,6 @@ rayon = "1.3.0"
string_cache = "0.8.0"
env_logger = "0.9.0"
log = "0.4.14"
pyo3-log = "0.7.0"
log-panics = "2.0.0"
[dependencies.state-map]
@@ -31,16 +34,23 @@ crate-type = ["cdylib", "rlib"]
[dependencies.clap]
version = "4.0.15"
features = ["cargo"]
optional = true
[dependencies.pyo3]
version = "0.17.1"
features = ["extension-module"]
optional = true
[dependencies.pyo3-log]
version = "0.7.0"
optional = true
[dependencies.tikv-jemallocator]
version = "0.5.0"
optional = true
[features]
default = ["jemalloc"]
default = ["clap", "jemalloc", "pyo3"]
jemalloc = ["tikv-jemallocator"]
no-progress-bars = []
pyo3 = ["dep:pyo3", "dep:pyo3-log"]

View File

@@ -20,9 +20,11 @@
// of arguments - this hopefully doesn't make the code unclear
// #[allow(clippy::too_many_arguments)] is therefore used around some functions
use log::{info, warn, LevelFilter};
use log::{info, warn};
#[cfg(feature = "pyo3")]
use pyo3::{exceptions, prelude::*};
#[cfg(feature = "clap")]
use clap::{crate_authors, crate_description, crate_name, crate_version, Arg, Command};
use indicatif::{ProgressBar, ProgressStyle};
use rayon::prelude::*;
@@ -117,6 +119,7 @@ pub struct Config {
verify: bool,
}
#[cfg(feature = "clap")]
impl Config {
/// Build up config from command line arguments
pub fn parse_arguments() -> Config {
@@ -747,6 +750,7 @@ impl Config {
/// Default arguments are equivalent to using the command line tool
/// No default's are provided for db_url or room_id since these arguments
/// are compulsory (so that new() act's like parse_arguments())
#[cfg(feature = "pyo3")]
#[allow(clippy::too_many_arguments)]
#[pyfunction(
// db_url has no default
@@ -802,14 +806,15 @@ fn run_compression(
}
/// Python module - "import synapse_compress_state" to use
#[cfg(feature = "pyo3")]
#[pymodule]
fn synapse_compress_state(_py: Python, m: &PyModule) -> PyResult<()> {
let _ = pyo3_log::Logger::default()
// don't send out anything lower than a warning from other crates
.filter(LevelFilter::Warn)
.filter(log::LevelFilter::Warn)
// don't log warnings from synapse_compress_state, the synapse_auto_compressor handles these
// situations and provides better log messages
.filter_target("synapse_compress_state".to_owned(), LevelFilter::Debug)
.filter_target("synapse_compress_state".to_owned(), log::LevelFilter::Debug)
.install();
// ensure any panics produce error messages in the log
log_panics::init();

View File

@@ -4,6 +4,10 @@ authors = ["William Ashton"]
version = "0.1.3"
edition = "2018"
[[bin]]
name = "synapse_auto_compressor"
required-features = ["clap"]
[package.metadata.maturin]
requires-python = ">=3.7"
project-url = {Source = "https://github.com/matrix-org/rust-synapse-compress-state"}
@@ -18,12 +22,11 @@ postgres = "0.19.0"
postgres-openssl = "0.5.0"
rand = "0.8.0"
serial_test = "0.9.0"
synapse_compress_state = { path = "../", features = ["no-progress-bars"] }
synapse_compress_state = { path = "../", features = ["no-progress-bars"], default-features = false }
env_logger = "0.9.0"
log = "0.4.14"
log-panics = "2.0.0"
anyhow = "1.0.42"
pyo3-log = "0.7.0"
# Needed for pyo3 support
[lib]
@@ -32,15 +35,22 @@ crate-type = ["cdylib", "rlib"]
[dependencies.clap]
version = "4.0.15"
features = ["cargo"]
optional = true
[dependencies.pyo3]
version = "0.17.1"
features = ["extension-module"]
optional = true
[dependencies.pyo3-log]
version = "0.7.0"
optional = true
[dependencies.tikv-jemallocator]
version = "0.5.0"
optional = true
[features]
default = ["jemalloc"]
jemalloc = ["tikv-jemallocator"]
default = ["clap", "jemalloc", "pyo3"]
jemalloc = ["tikv-jemallocator", "synapse_compress_state/jemalloc"]
pyo3 = ["dep:pyo3", "dep:pyo3-log", "synapse_compress_state/pyo3"]

View File

@@ -7,7 +7,9 @@
//! on space reductions
use anyhow::Result;
#[cfg(feature = "pyo3")]
use log::{error, LevelFilter};
#[cfg(feature = "pyo3")]
use pyo3::{
exceptions::PyRuntimeError, prelude::pymodule, types::PyModule, PyErr, PyResult, Python,
};
@@ -56,6 +58,7 @@ impl FromStr for LevelInfo {
}
// PyO3 INTERFACE STARTS HERE
#[cfg(feature = "pyo3")]
#[pymodule]
fn synapse_auto_compressor(_py: Python, m: &PyModule) -> PyResult<()> {
let _ = pyo3_log::Logger::default()