-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathlib.rs
More file actions
65 lines (54 loc) · 1.84 KB
/
lib.rs
File metadata and controls
65 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
pub(crate) mod constants;
mod table_provider;
mod udf;
mod utils;
use pyo3::exceptions::PyRuntimeWarning;
use pyo3::prelude::*;
use pyo3::types::PyTuple;
use pyo3::{intern, wrap_pymodule};
const VERSION: &str = env!("CARGO_PKG_VERSION");
#[pyfunction]
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(intern!(py, "warnings"))?;
let warning = PyRuntimeWarning::new_err(
"geodatafusion has not been compiled in release mode. Performance will be degraded.",
);
let args = PyTuple::new(py, vec![warning])?;
warnings_mod.call_method1(intern!(py, "warn"), args)?;
}
Ok(())
}
/// A Python module implemented in Rust.
#[pymodule]
fn _rust(py: Python, m: &Bound<PyModule>) -> PyResult<()> {
check_debug_build(py)?;
m.add_wrapped(wrap_pyfunction!(___version))?;
let native_mod = wrap_pymodule!(udf::native::native)(py);
m.add_submodule(native_mod.bind(py))?;
py.import(intern!(py, "sys"))?
.getattr(intern!(py, "modules"))?
.set_item("geodatafusion.native", native_mod)?;
let geohash_mod = wrap_pymodule!(udf::geohash::geohash)(py);
m.add_submodule(geohash_mod.bind(py))?;
py.import(intern!(py, "sys"))?
.getattr(intern!(py, "modules"))?
.set_item("geodatafusion.geohash", geohash_mod)?;
let geo_mod = wrap_pymodule!(udf::geo::geo)(py);
m.add_submodule(geo_mod.bind(py))?;
py.import(intern!(py, "sys"))?
.getattr(intern!(py, "modules"))?
.set_item("geodatafusion.geo", geo_mod)?;
m.add_function(wrap_pyfunction!(
table_provider::flatgeobuf::new_flatgeobuf,
m
)?)?;
Ok(())
}