diff --git a/arro3-compute/src/lib.rs b/arro3-compute/src/lib.rs index 9049ea6..d8d77b3 100644 --- a/arro3-compute/src/lib.rs +++ b/arro3-compute/src/lib.rs @@ -1,4 +1,7 @@ +use pyo3::exceptions::PyRuntimeWarning; +use pyo3::intern; use pyo3::prelude::*; +use pyo3::types::PyTuple; mod aggregate; mod arith; @@ -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) -> PyResult<()> { +fn _compute(py: Python, m: &Bound) -> PyResult<()> { + check_debug_build(py)?; + m.add_wrapped(wrap_pyfunction!(___version))?; m.add_wrapped(wrap_pyfunction!(aggregate::max))?; diff --git a/arro3-core/src/lib.rs b/arro3-core/src/lib.rs index 168bea5..936310f 100644 --- a/arro3-core/src/lib.rs +++ b/arro3-core/src/lib.rs @@ -1,4 +1,7 @@ +use pyo3::exceptions::PyRuntimeWarning; +use pyo3::intern; use pyo3::prelude::*; +use pyo3::types::PyTuple; mod accessors; mod constructors; @@ -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) -> PyResult<()> { +fn _core(py: Python, m: &Bound) -> PyResult<()> { + check_debug_build(py)?; + m.add_wrapped(wrap_pyfunction!(___version))?; m.add_class::()?; diff --git a/arro3-io/src/lib.rs b/arro3-io/src/lib.rs index 23d1beb..3705acf 100644 --- a/arro3-io/src/lib.rs +++ b/arro3-io/src/lib.rs @@ -1,4 +1,7 @@ +use pyo3::exceptions::PyRuntimeWarning; +use pyo3::intern; use pyo3::prelude::*; +use pyo3::types::PyTuple; mod csv; mod error; @@ -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) -> PyResult<()> { + check_debug_build(py)?; + m.add_wrapped(wrap_pyfunction!(___version))?; pyo3_object_store::register_store_module(py, m, "arro3.io")?;