Skip to content

Commit

Permalink
Raise RuntimeWarning when compiled in debug mode (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Nov 7, 2024
1 parent 2c73b76 commit 652eb6d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
23 changes: 22 additions & 1 deletion arro3-compute/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 aggregate;
mod arith;
Expand All @@ -17,8 +20,26 @@ 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(
"arro3.compute 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(())
}

#[pymodule]
fn _compute(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
fn _compute(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;

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

m.add_wrapped(wrap_pyfunction!(aggregate::max))?;
Expand Down
23 changes: 22 additions & 1 deletion arro3-core/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 accessors;
mod constructors;
Expand All @@ -10,9 +13,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(
"arro3.core 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 _core(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
fn _core(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;

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

m.add_class::<pyo3_arrow::PyArray>()?;
Expand Down
21 changes: 21 additions & 0 deletions arro3-io/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 csv;
mod error;
Expand All @@ -14,8 +17,26 @@ 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(
"arro3.io 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(())
}

#[pymodule]
fn _io(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;

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

pyo3_object_store::register_store_module(py, m, "arro3.io")?;
Expand Down

0 comments on commit 652eb6d

Please sign in to comment.