Skip to content

Commit

Permalink
Raise RuntimeWarning for debug builds (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Nov 7, 2024
1 parent e6d0f87 commit c0a8556
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions obstore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use pyo3::exceptions::PyRuntimeWarning;
use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::PyTuple;

mod attributes;
mod buffered;
Expand All @@ -21,9 +24,27 @@ fn ___version() -> &'static str {
VERSION
}

/// Raise RuntimeWarning for debug builds
#[pyfunction]
fn check_debug_build(py: Python) -> PyResult<()> {
#[cfg(debug_assertions)]
{
let warnings_mod = py.import_bound(intern!(py, "warnings"))?;
let warning = PyRuntimeWarning::new_err(
"obstore has not been compiled in release mode. Performance will be degraded.",
);
let args = PyTuple::new_bound(py, vec![warning.into_py(py)]);
warnings_mod.call_method1(intern!(py, "warn"), args)?;
}

Ok(())
}

/// A Python module implemented in Rust.
#[pymodule]
fn _obstore(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;

m.add_wrapped(wrap_pyfunction!(___version))?;

pyo3_object_store::register_store_module(py, m, "obstore")?;
Expand Down

0 comments on commit c0a8556

Please sign in to comment.