Skip to content

Commit

Permalink
Make PYO3 dependency option for origen_metal crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ginty authored and rlaj committed Jun 10, 2024
1 parent 374eed7 commit 8e65881
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion rust/origen_metal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ categories = ["embedded", "science"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
# Enables the Python API, when not enabled (the default) origen_metal is a pure Rust library that
# can only be used from Rust
python = ["dep:pyo3"]

[dependencies]
lazy_static = "1"
time = "0.1"
termcolor = "1"
regex = "1"
tempfile = "3"
pyo3 = {version = "0.19.1", features = ["extension-module"]}
pyo3 = {version = "0.19.1", features = ["extension-module"], optional = true}
serde = {version = "1.0", features = ["derive"]}
toml = "0.5"
toml_edit = "0.21.0"
Expand Down
2 changes: 2 additions & 0 deletions rust/origen_metal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ impl BaseError for Error {

// To add a conversion from other type of errors

#[cfg(feature = "python")]
impl std::convert::From<Error> for pyo3::PyErr {
fn from(err: Error) -> pyo3::PyErr {
pyo3::exceptions::PyRuntimeError::new_err(err.to_string())
}
}

#[cfg(feature = "python")]
impl std::convert::From<pyo3::PyErr> for Error {
fn from(err: pyo3::PyErr) -> Self {
pyo3::Python::with_gil(|py| {
Expand Down
2 changes: 1 addition & 1 deletion rust/pyapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["cdylib"]

[dependencies]
origen = { path = "../origen" }
origen_metal = { path = "../origen_metal" }
origen_metal = { path = "../origen_metal", features = ["python"] }
pyapi_metal = { path = "../pyapi_metal", package = "pyapi_metal" }
num-bigint = "0.4.0"
num-traits = "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion rust/pyapi_metal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "origen_metal"
crate-type = ["cdylib", "lib"]

[dependencies]
origen_metal = { path = "../origen_metal" }
origen_metal = { path = "../origen_metal", features = ["python"] }
indexmap = "1.3.0"
num-bigint = "0.4.0"

Expand Down

0 comments on commit 8e65881

Please sign in to comment.