NREL / routee-compass

An energy-aware routing engine
https://nrel.github.io/routee-compass/
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

Fix PyO3 0.21 deprecation warnings #222

Closed kylecarow closed 4 months ago

kylecarow commented 4 months ago

Also add rasterio and gdal imports at the top of the OSM example notebook to fail faster (rather than waiting for grade data to download on slow PyCon wifi)

https://pyo3.rs/v0.21.2/migration#from-020-to-021

According to the above link, there are some API changes for 0.21 to remove GIL markers. This means changing the pymodule def:

#[pymodule]
- fn routee_compass_py(_py: Python, m: &PyModule) -> PyResult<()> {
+ fn routee_compass_py(m: &Bound<'_, PyModule>) -> PyResult<()> {

As well as classmethod defs (though this one could be a staticmethod and it works just fine, since we don't use the pyclass):

- #[classmethod]
- pub fn _from_config_toml_string(
-     _cls: &PyType,
-     config_string: String,
-     original_file_path: String,
- ) -> PyResult<#name> {
+ #[staticmethod]
+ pub fn _from_config_toml_string(
+     config_string: String,
+     original_file_path: String,
+ ) -> PyResult<#name> {

Also in the OSM example I had issues with failing imports during grade data building, so I added a try/except at the top to catch those errors sooner.

Fixes #167