Skip to content

Commit

Permalink
Fully remove pyo3 as a dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <ryan@bottriell.ca>
  • Loading branch information
rydrman committed Apr 10, 2022
1 parent 896ae4e commit 75f2ee6
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 394 deletions.
160 changes: 1 addition & 159 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ indexmap = "1.7.0"
itertools = "0.9"
lazy_static = "1.4.0"
once_cell = "1.8.0"
pyo3 = { version = "0.14.1", features = ["hashbrown", "auto-initialize"] }
regex = "1.5.4"
relative-path = "1.3.2"
ring = "0.16.15"
Expand Down
47 changes: 1 addition & 46 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// https://github.com/imageworks/spk

use pyo3::{exceptions, prelude::*};

use crate::solve;

use super::{api, build, test};
Expand All @@ -17,7 +15,6 @@ pub enum Error {
Serde(serde_yaml::Error),
Solve(crate::solve::Error),
String(String),
PyErr(PyErr),

// API Errors
InvalidVersionError(api::InvalidVersionError),
Expand All @@ -42,16 +39,7 @@ pub enum Error {
impl Error {
/// Wraps an error message with a prefix, creating a contextual but generic error
pub fn wrap<S: AsRef<str>>(prefix: S, err: Self) -> Self {
// preserve PyErr types
match err {
Error::PyErr(pyerr) => Error::PyErr(Python::with_gil(|py| {
PyErr::from_type(
pyerr.ptype(py),
format!("{}: {}", prefix.as_ref(), pyerr.pvalue(py)),
)
})),
err => Error::String(format!("{}: {:?}", prefix.as_ref(), err)),
}
Error::String(format!("{}: {:?}", prefix.as_ref(), err))
}

/// Wraps an error message with a prefix, creating a contextual error
Expand All @@ -62,12 +50,6 @@ impl Error {

impl std::error::Error for Error {}

impl From<PyErr> for Error {
fn from(err: PyErr) -> Error {
Error::PyErr(err)
}
}

impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error::IO(err)
Expand Down Expand Up @@ -97,30 +79,3 @@ impl std::fmt::Display for Error {
f.write_str(&format!("{:?}", self))
}
}

impl From<Error> for PyErr {
fn from(err: Error) -> PyErr {
match err {
Error::IO(err) => err.into(),
Error::SPFS(spfs::Error::IO(err)) => err.into(),
Error::SPFS(err) => exceptions::PyRuntimeError::new_err(err.to_string()),
Error::Serde(err) => exceptions::PyRuntimeError::new_err(err.to_string()),
Error::String(msg) => exceptions::PyRuntimeError::new_err(msg),
Error::Solve(_err) => todo!(),
Error::InvalidBuildError(err) => exceptions::PyValueError::new_err(err.message),
Error::InvalidVersionError(err) => exceptions::PyValueError::new_err(err.message),
Error::InvalidNameError(err) => exceptions::PyValueError::new_err(err.message),
Error::PackageNotFoundError(pkg) => {
exceptions::PyFileNotFoundError::new_err(format!("Package not found: {}", pkg))
}
Error::VersionExistsError(pkg) => {
exceptions::PyFileExistsError::new_err(format!("Version already exists: {}", pkg))
}
Error::Build(_err) => todo!(),
Error::Collection(_err) => todo!(),
Error::Test(_err) => todo!(),
Error::NoEnvironment => todo!(),
Error::PyErr(err) => err,
}
}
}
Loading

0 comments on commit 75f2ee6

Please sign in to comment.