Skip to content

Commit fc2a563

Browse files
authored
Python: Runtime warning when compiled in debug mode (#859)
Closes #851
1 parent 01648f7 commit fc2a563

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

python/geoarrow-compute/src/lib.rs

Lines changed: 20 additions & 1 deletion
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
mod algorithm;
36
pub mod broadcasting;
47
pub mod ffi;
@@ -11,9 +14,25 @@ fn ___version() -> &'static str {
1114
VERSION
1215
}
1316

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

1938
// Top-level array/chunked array functions

python/geoarrow-core/src/lib.rs

Lines changed: 20 additions & 1 deletion
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
mod constructors;
36
pub(crate) mod crs;
47
pub mod ffi;
@@ -12,9 +15,25 @@ fn ___version() -> &'static str {
1215
VERSION
1316
}
1417

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

2039
m.add_class::<pyo3_geoarrow::PyGeometry>()?;

python/geoarrow-io/src/lib.rs

Lines changed: 20 additions & 1 deletion
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
pub(crate) mod crs;
36
pub mod error;
47
// pub mod ffi;
@@ -12,9 +15,25 @@ fn ___version() -> &'static str {
1215
VERSION
1316
}
1417

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

2039
// Async IO

0 commit comments

Comments
 (0)