Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at python bindings for zarr store EAR-1148 #39

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

mpiannucci
Copy link
Contributor

Putting this up just for visibility as i figure out the most efficient way to bind errors and results

Copy link
Collaborator

@paraseba paraseba left a comment

Choose a reason for hiding this comment

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

Amazing stuff!

name: wheels-sdist
path: dist

release:
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we comment out this to avoid mistakes before we are ready to release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in the subfolder so it won't run until it's moved to the root I believe. I'll confirm tho

key_ranges: Vec<(String, ByteRange)>,
) -> RustStoreResult<Vec<Option<Vec<u8>>>> {
// Not sure how to hanlde ARC requirement yet
//let result = self.store.get_partial_values(&key, key_ranges.iter()).await?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paraseba I am not sure the best way to handle this function, since self on the zarr store expects an Arc. Any ideas? If i want to wrap the inner store in an Arc then i need a mutex for it to mutable, but then that messes with it being an arc haha

Copy link
Contributor Author

@mpiannucci mpiannucci Aug 30, 2024

Choose a reason for hiding this comment

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

Also since python expections are not values, they are top level only, so we cant pass a vactor of them. So we have a choice between bubbling errors to the top or ignoring inner errors and returning None for keys that fail. The zarr spec says keys that dont exist return None but thats maybe not comprehensive

@@ -0,0 +1,72 @@
/target
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a bit more comprehensive that we may need? Would it make sense to add a few lines to the .ignore file at the root instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be cleaned up.. this is what is autogenned from the maturin project template

use pyo3::{exceptions::PyValueError, PyErr};

/// A simple wrapper around the StoreError to make it easier to convert to a PyErr
pub struct RustStoreError(pub StoreError);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are using thiserror crate for this kind o things and it works very well. It gives you Error implementations, including the display parts and the error sourcing.

Copy link
Contributor Author

@mpiannucci mpiannucci Sep 3, 2024

Choose a reason for hiding this comment

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

We need this in order to map theStoreErrorto PyError, which is a python exception. We cannot impl the From<PyError> on StoreError in this crate because of orphan rules

// and the lifetime of the stream is tied to the lifetime of the store. So the return
// value is valid as long as the store is valid. Rust has no way to express this to
// the Python runtime so we have to do it manually.
fn pin_extend_stream<'a>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Really happy we have a way to do this, even if it's unsafe.

Can we find a way to make this less generic on 'a by tying it to the lifetime of IcechunkStore. This is really lying right? If IcechunkStore is dropped, this value will fail, it's not really 'static for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct this is lying. The reason is that python PyClass wrpapers have no support for lifetime annotations, so you cannot enforce the lifetimes. Its really hacky and there is no real other way to manage it that i can think of unless we change downstreamn implementation to not be bound to the lifetime of the downstream store

@mpiannucci mpiannucci changed the title First pass at python bindings for zarr store First pass at python bindings for zarr store EAR-1148 Sep 3, 2024
@mpiannucci mpiannucci marked this pull request as ready for review September 3, 2024 19:24
@mpiannucci mpiannucci merged commit 8461682 into main Sep 3, 2024
1 check passed
@mpiannucci mpiannucci deleted the python-bindings branch September 3, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants