Skip to content

Commit 652eb6d

Browse files
authored
Raise RuntimeWarning when compiled in debug mode (#255)
1 parent 2c73b76 commit 652eb6d

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

arro3-compute/src/lib.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use pyo3::exceptions::PyRuntimeWarning;
2+
use pyo3::intern;
13
use pyo3::prelude::*;
4+
use pyo3::types::PyTuple;
25

36
mod aggregate;
47
mod arith;
@@ -17,8 +20,26 @@ fn ___version() -> &'static str {
1720
VERSION
1821
}
1922

23+
/// Raise RuntimeWarning for debug builds
24+
#[pyfunction]
25+
fn check_debug_build(py: Python) -> PyResult<()> {
26+
#[cfg(debug_assertions)]
27+
{
28+
let warnings_mod = py.import_bound(intern!(py, "warnings"))?;
29+
let warning = PyRuntimeWarning::new_err(
30+
"arro3.compute has not been compiled in release mode. Performance will be degraded.",
31+
);
32+
let args = PyTuple::new_bound(py, vec![warning.into_py(py)]);
33+
warnings_mod.call_method1(intern!(py, "warn"), args)?;
34+
}
35+
36+
Ok(())
37+
}
38+
2039
#[pymodule]
21-
fn _compute(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
40+
fn _compute(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
41+
check_debug_build(py)?;
42+
2243
m.add_wrapped(wrap_pyfunction!(___version))?;
2344

2445
m.add_wrapped(wrap_pyfunction!(aggregate::max))?;

arro3-core/src/lib.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use pyo3::exceptions::PyRuntimeWarning;
2+
use pyo3::intern;
13
use pyo3::prelude::*;
4+
use pyo3::types::PyTuple;
25

36
mod accessors;
47
mod constructors;
@@ -10,9 +13,27 @@ fn ___version() -> &'static str {
1013
VERSION
1114
}
1215

16+
/// Raise RuntimeWarning for debug builds
17+
#[pyfunction]
18+
fn check_debug_build(py: Python) -> PyResult<()> {
19+
#[cfg(debug_assertions)]
20+
{
21+
let warnings_mod = py.import_bound(intern!(py, "warnings"))?;
22+
let warning = PyRuntimeWarning::new_err(
23+
"arro3.core has not been compiled in release mode. Performance will be degraded.",
24+
);
25+
let args = PyTuple::new_bound(py, vec![warning.into_py(py)]);
26+
warnings_mod.call_method1(intern!(py, "warn"), args)?;
27+
}
28+
29+
Ok(())
30+
}
31+
1332
/// A Python module implemented in Rust.
1433
#[pymodule]
15-
fn _core(_py: Python, m: &Bound<PyModule>) -> PyResult<()> {
34+
fn _core(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
35+
check_debug_build(py)?;
36+
1637
m.add_wrapped(wrap_pyfunction!(___version))?;
1738

1839
m.add_class::<pyo3_arrow::PyArray>()?;

arro3-io/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
use pyo3::exceptions::PyRuntimeWarning;
2+
use pyo3::intern;
13
use pyo3::prelude::*;
4+
use pyo3::types::PyTuple;
25

36
mod csv;
47
mod error;
@@ -14,8 +17,26 @@ fn ___version() -> &'static str {
1417
VERSION
1518
}
1619

20+
/// Raise RuntimeWarning for debug builds
21+
#[pyfunction]
22+
fn check_debug_build(py: Python) -> PyResult<()> {
23+
#[cfg(debug_assertions)]
24+
{
25+
let warnings_mod = py.import_bound(intern!(py, "warnings"))?;
26+
let warning = PyRuntimeWarning::new_err(
27+
"arro3.io has not been compiled in release mode. Performance will be degraded.",
28+
);
29+
let args = PyTuple::new_bound(py, vec![warning.into_py(py)]);
30+
warnings_mod.call_method1(intern!(py, "warn"), args)?;
31+
}
32+
33+
Ok(())
34+
}
35+
1736
#[pymodule]
1837
fn _io(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
38+
check_debug_build(py)?;
39+
1940
m.add_wrapped(wrap_pyfunction!(___version))?;
2041

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

0 commit comments

Comments
 (0)