-
Notifications
You must be signed in to change notification settings - Fork 13
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
list_refs #318
base: main
Are you sure you want to change the base?
list_refs #318
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,38 @@ struct PyIcechunkStore { | |
store: Arc<RwLock<Store>>, | ||
} | ||
|
||
#[pyclass(name = "Ref")] | ||
#[derive(Debug, Clone, Eq, PartialEq, Hash)] | ||
pub enum PyRef { | ||
Tag { name: String }, | ||
Branch { name: String }, | ||
} | ||
|
||
impl From<Ref> for PyRef { | ||
fn from(reference: Ref) -> Self { | ||
match reference { | ||
Ref::Tag(name) => Self::Tag { name }, | ||
Ref::Branch(name) => Self::Branch { name }, | ||
} | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PyRef { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beautiful |
||
fn __repr__(&self) -> PyResult<String> { | ||
match self { | ||
PyRef::Branch { name } => Ok(format!("Branch('{}')", name)), | ||
PyRef::Tag { name } => Ok(format!("Tag('{}')", name)), | ||
} | ||
} | ||
fn __str__(&self) -> PyResult<String> { | ||
match self { | ||
PyRef::Branch { name } => Ok(name.to_owned()), | ||
PyRef::Tag { name } => Ok(name.to_owned()), | ||
} | ||
} | ||
} | ||
|
||
#[pyclass(name = "StoreConfig")] | ||
#[derive(Clone, Debug, Default)] | ||
struct PyStoreConfig { | ||
|
@@ -432,6 +464,25 @@ impl PyIcechunkStore { | |
Ok(snapshot_id.to_string()) | ||
} | ||
|
||
fn list_refs<'py>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also provide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a python test that exercises this new function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I can do both. I'd like some input on #318 (comment) first before I tackle those. |
||
&'py self, | ||
py: Python<'py>, | ||
) -> PyIcechunkStoreResult<Bound<'py, PyList>> { | ||
pyo3_asyncio_0_21::tokio::get_runtime().block_on(async move { | ||
let store = self.store.read().await; | ||
let list = store | ||
.list_refs() | ||
.await? | ||
.into_iter() | ||
.map(|parent| { | ||
let parent = Into::<PyRef>::into(parent); | ||
Python::with_gil(|py| parent.into_py(py)) | ||
}) | ||
.collect::<Vec<_>>(); | ||
Ok(PyList::new_bound(py, list)) | ||
}) | ||
} | ||
|
||
fn async_commit<'py>( | ||
&'py self, | ||
py: Python<'py>, | ||
|
@@ -1044,6 +1095,7 @@ fn _icechunk_python(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { | |
m.add_class::<PyStoreConfig>()?; | ||
m.add_class::<PySnapshotMetadata>()?; | ||
m.add_class::<PyVirtualRefConfig>()?; | ||
m.add_class::<PyRef>()?; | ||
m.add_function(wrap_pyfunction!(pyicechunk_store_exists, m)?)?; | ||
m.add_function(wrap_pyfunction!(async_pyicechunk_store_exists, m)?)?; | ||
m.add_function(wrap_pyfunction!(pyicechunk_store_create, m)?)?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the model we want to return to users?
Alternatives could be:
BranchName(str)
andTagName(str)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, forgot to comment. i like your approach best, but I'd like to see how easy/hard is to pattern match the result in python. Probably tests will show me that.
Other option would be to have separate functions,
list_tags
andlist_branches
, or maybe the three of them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that tags and branches can be in separate functions and that simplifies a lot from the Python user perspective