Skip to content

Commit

Permalink
more anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
ctb committed Aug 18, 2023
1 parent 071be2c commit 7f0b517
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "pyo3_branchwater"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.18.1", features = ["extension-module"] }
pyo3 = { version = "0.18.1", features = ["extension-module", "anyhow"] }
rayon = "1.5.1"
serde = { version = "1.0.136", features = ["derive"] }
sourmash = "0.11.0"
Expand Down
17 changes: 3 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// not orig. This is different from sourmash...

use pyo3::prelude::*;
use pyo3::create_exception;
use pyo3::exceptions::PyException;

use rayon::prelude::*;

Expand All @@ -29,14 +27,6 @@ use sourmash::signature::{Signature, SigsTrait};
use sourmash::sketch::minhash::{max_hash_for_scaled, KmerMinHash};
use sourmash::sketch::Sketch;

create_exception!(pymagsearch, SomeError, pyo3::exceptions::PyException);

impl std::convert::From<SomeError> for PyErr {
fn from(err: SomeError) -> PyErr {
PyException::new_err(err.to_string())
}
}

/// check to see if two KmerMinHash are compatible.
///
/// CTB note: despite the name, downsampling is not performed?
Expand Down Expand Up @@ -650,7 +640,7 @@ fn do_manysearch(querylist_path: String,
ksize: u8,
scaled: usize,
output_path: String
) -> PyResult<u8> {
) -> anyhow::Result<u8> {
match manysearch(querylist_path, siglist_path, threshold, ksize, scaled,
Some(output_path)) {
Ok(_) => Ok(0),
Expand All @@ -669,7 +659,7 @@ fn do_countergather(query_filename: String,
scaled: usize,
output_path_prefetch: Option<String>,
output_path_gather: Option<String>,
) -> PyResult<u8> {
) -> anyhow::Result<u8> {
match countergather(query_filename, siglist_path, threshold_bp,
ksize, scaled,
output_path_prefetch,
Expand All @@ -688,7 +678,7 @@ fn do_multigather(query_filenames: String,
threshold_bp: usize,
ksize: u8,
scaled: usize
) -> PyResult<u8> {
) -> anyhow::Result<u8> {
match multigather(query_filenames, siglist_path, threshold_bp,
ksize, scaled) {
Ok(_) => Ok(0),
Expand All @@ -709,7 +699,6 @@ fn pyo3_branchwater(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(do_manysearch, m)?)?;
m.add_function(wrap_pyfunction!(do_countergather, m)?)?;
m.add_function(wrap_pyfunction!(do_multigather, m)?)?;
m.add("SomeError", _py.get_type::<SomeError>())?;
m.add_function(wrap_pyfunction!(get_num_threads, m)?)?;
Ok(())
}

0 comments on commit 7f0b517

Please sign in to comment.