Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 129 additions & 42 deletions rust/Cargo.lock

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

16 changes: 12 additions & 4 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ name = "_rustgrimp"
crate-type = ["cdylib", "rlib"]

[dependencies]
log = "0.4.19"
pyo3-log = "0.12.1"
serde_json = "1.0.103"
rayon = "1.10"
petgraph = "0.6.5"
bimap = "0.6.3"
slotmap = "1.0.7"
getset = "0.1.3"
derive-new = "0.7.0"
lazy_static = "1.5.0"
string-interner = "0.18.0"
thiserror = "2.0.11"
itertools = "0.14.0"
tap = "1.0.1"
rustc-hash = "2.1.0"
indexmap = "2.7.1"

[dependencies.pyo3]
version = "0.23.4"

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]

[dev-dependencies]
serde_json = "1.0.137"
29 changes: 29 additions & 0 deletions rust/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::exceptions::{ModuleNotPresent, NoSuchContainer};
use pyo3::exceptions::PyValueError;
use pyo3::PyErr;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum GrimpError {
#[error("Module {0} is not present in the graph.")]
ModuleNotPresent(String),

#[error("Container {0} does not exist.")]
NoSuchContainer(String),

#[error("Modules have shared descendants.")]
SharedDescendants,
}

pub type GrimpResult<T> = Result<T, GrimpError>;

impl From<GrimpError> for PyErr {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but feels like we have a mixture of Python concerns and pure Rust concerns in this module. I think there's benefit in keeping them separate - e.g. to keep lib.rs for the py03 stuff and then everything else is pure Rust.

What do you think about moving this implementation either to exceptions.rs or to lib.rs? (Will that even compile?) We could leave the definition of GrimpError and GrimpResult here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feeling about this one. Happy to change it.

fn from(value: GrimpError) -> Self {
// A default mapping from `GrimpError`s to python exceptions.
match value {
GrimpError::ModuleNotPresent(_) => ModuleNotPresent::new_err(value.to_string()),
GrimpError::NoSuchContainer(_) => NoSuchContainer::new_err(value.to_string()),
GrimpError::SharedDescendants => PyValueError::new_err(value.to_string()),
}
}
}
4 changes: 4 additions & 0 deletions rust/src/exceptions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use pyo3::create_exception;

create_exception!(_rustgrimp, ModuleNotPresent, pyo3::exceptions::PyException);
create_exception!(_rustgrimp, NoSuchContainer, pyo3::exceptions::PyException);
Loading