Skip to content

Commit

Permalink
Update pyo3 and numpy to 0.20.0
Browse files Browse the repository at this point in the history
This commit updates PyO3 to the latest release 0.20.0 [1] and also moves
rust-numpy to 0.20.0 [2] as well. The major change for rustworkx is
official support for Python 3.12.0 final. We were previously using the
3.12 pre-release support in PyO3 to publish rustworkx for 3.12, but
moving to the latest PyO3 officially supports the stable releases of
3.12. The are some small changes needed to adapt to API changes in PyO3,
mostly around updates to the `PyDict.get_item()` api.

[1] https://github.com/PyO3/pyo3/releases/tag/v0.20.0
[2] https://github.com/PyO3/rust-numpy/releases/tag/v0.20.0
  • Loading branch information
mtreinish committed Oct 15, 2023
1 parent c216efa commit 809bfbd
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 53 deletions.
76 changes: 36 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fixedbitset = "0.4.2"
hashbrown = { version = ">=0.13, <0.15", features = ["rayon"] }
indexmap = { version = ">=1.9, <3", features = ["rayon"] }
num-traits = "0.2"
numpy = "0.19.0"
numpy = "0.20.0"
petgraph = "0.6.4"
rand = "0.8"
rand_pcg = "0.3"
Expand Down Expand Up @@ -60,7 +60,7 @@ serde_json = "1.0"
rustworkx-core = { path = "rustworkx-core", version = "=0.14.0" }

[dependencies.pyo3]
version = "0.19.2"
version = "0.20.0"
features = ["extension-module", "hashbrown", "num-bigint", "num-complex", "indexmap"]

[dependencies.ndarray]
Expand Down
18 changes: 12 additions & 6 deletions src/digraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,27 +332,33 @@ impl PyDiGraph {

fn __setstate__(&mut self, py: Python, state: PyObject) -> PyResult<()> {
let dict_state = state.downcast::<PyDict>(py)?;
let nodes_lst = dict_state.get_item("nodes").unwrap().downcast::<PyList>()?;
let edges_lst = dict_state.get_item("edges").unwrap().downcast::<PyList>()?;
let nodes_lst = dict_state
.get_item("nodes")?
.unwrap()
.downcast::<PyList>()?;
let edges_lst = dict_state
.get_item("edges")?
.unwrap()
.downcast::<PyList>()?;
self.graph = StablePyGraph::<Directed>::new();
let dict_state = state.downcast::<PyDict>(py)?;
self.multigraph = dict_state
.get_item("multigraph")
.get_item("multigraph")?
.unwrap()
.downcast::<PyBool>()?
.extract()?;
self.node_removed = dict_state
.get_item("nodes_removed")
.get_item("nodes_removed")?
.unwrap()
.downcast::<PyBool>()?
.extract()?;
let attrs = match dict_state.get_item("attrs") {
let attrs = match dict_state.get_item("attrs")? {
Some(attr) => attr.into(),
None => py.None(),
};
self.attrs = attrs;
self.check_cycle = dict_state
.get_item("check_cycle")
.get_item("check_cycle")?
.unwrap()
.downcast::<PyBool>()?
.extract()?;
Expand Down
16 changes: 11 additions & 5 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,21 +229,27 @@ impl PyGraph {

fn __setstate__(&mut self, py: Python, state: PyObject) -> PyResult<()> {
let dict_state = state.downcast::<PyDict>(py)?;
let nodes_lst = dict_state.get_item("nodes").unwrap().downcast::<PyList>()?;
let edges_lst = dict_state.get_item("edges").unwrap().downcast::<PyList>()?;
let nodes_lst = dict_state
.get_item("nodes")?
.unwrap()
.downcast::<PyList>()?;
let edges_lst = dict_state
.get_item("edges")?
.unwrap()
.downcast::<PyList>()?;

self.graph = StablePyGraph::<Undirected>::default();
self.multigraph = dict_state
.get_item("multigraph")
.get_item("multigraph")?
.unwrap()
.downcast::<PyBool>()?
.extract()?;
self.node_removed = dict_state
.get_item("nodes_removed")
.get_item("nodes_removed")?
.unwrap()
.downcast::<PyBool>()?
.extract()?;
self.attrs = match dict_state.get_item("attrs") {
self.attrs = match dict_state.get_item("attrs")? {
Some(attr) => attr.into(),
None => py.None(),
};
Expand Down

0 comments on commit 809bfbd

Please sign in to comment.