Skip to content

Commit

Permalink
Revert store enum changes
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Dec 12, 2024
1 parent fd0c6b4 commit 78d9642
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/chunk_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use zarrs::{
storage::{MaybeBytes, ReadableWritableListableStorage, StorageError, StoreKey},
};

use crate::{utils::PyErrExt, StoreConfigType};
use crate::{utils::PyErrExt, StoreConfig};

pub(crate) type Raw<'a> = (
// store
StoreConfigType,
StoreConfig,
// path
String,
// shape
Expand All @@ -36,7 +36,7 @@ pub(crate) type RawWithIndices<'a> = (
);

pub(crate) trait IntoItem<T, S>: std::marker::Sized {
fn store_config(&self) -> &StoreConfigType;
fn store_config(&self) -> &StoreConfig;
fn path(&self) -> &str;
fn into_item(
self,
Expand Down Expand Up @@ -93,7 +93,7 @@ impl ChunksItem for WithSubset {
}

impl<'a> IntoItem<Basic, ()> for Raw<'a> {
fn store_config(&self) -> &StoreConfigType {
fn store_config(&self) -> &StoreConfig {
&self.0
}

Expand All @@ -118,7 +118,7 @@ impl<'a> IntoItem<Basic, ()> for Raw<'a> {
}

impl IntoItem<WithSubset, &[u64]> for RawWithIndices<'_> {
fn store_config(&self) -> &StoreConfigType {
fn store_config(&self) -> &StoreConfig {
&self.0 .0
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator};
use rayon_iter_concurrent_limit::iter_concurrent_limit;
use std::borrow::Cow;
use std::sync::{Arc, Mutex};
use store::StoreConfigType;
use store::StoreConfig;
use unsafe_cell_slice::UnsafeCellSlice;
use zarrs::array::codec::{
ArrayToBytesCodecTraits, CodecOptions, CodecOptionsBuilder, StoragePartialDecoder,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct CodecPipelineImpl {
impl CodecPipelineImpl {
fn get_store_from_config(
&self,
config: &StoreConfigType,
config: &StoreConfig,
) -> PyResult<ReadableWritableListableStorage> {
let mut gstore = self.store.lock().map_err(|_| {
PyErr::new::<PyRuntimeError, _>("failed to lock the store mutex".to_string())
Expand Down
20 changes: 8 additions & 12 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ use crate::{runtime::tokio_block_on, utils::PyErrExt};
mod filesystem;
mod http;

#[gen_stub_pyclass]
#[pyclass(subclass)]
pub struct StoreConfig;

#[gen_stub_pyclass_enum]
pub enum StoreConfigType {
pub enum StoreConfig {
Filesystem(FilesystemStoreConfig),
Http(HttpStoreConfig),
// TODO: Add support for more stores
}

impl<'py> FromPyObject<'py> for StoreConfigType {
impl<'py> FromPyObject<'py> for StoreConfig {
fn extract_bound(store: &Bound<'py, PyAny>) -> PyResult<Self> {
let name = store.get_type().name()?;
let name = name.to_str()?;
match name {
"LocalStore" => {
let root: String = store.getattr("root")?.call_method0("__str__")?.extract()?;
Ok(StoreConfigType::Filesystem(FilesystemStoreConfig::new(
Ok(StoreConfig::Filesystem(FilesystemStoreConfig::new(
root,
)))
}
Expand All @@ -50,7 +46,7 @@ impl<'py> FromPyObject<'py> for StoreConfigType {
let storage_options: HashMap<String, Bound<'py, PyAny>> =
fs.getattr("storage_options")?.extract()?;
match fs_name {
"HTTPFileSystem" => Ok(StoreConfigType::Http(HttpStoreConfig::new(
"HTTPFileSystem" => Ok(StoreConfig::Http(HttpStoreConfig::new(
&path,
&storage_options,
)?)),
Expand All @@ -66,13 +62,13 @@ impl<'py> FromPyObject<'py> for StoreConfigType {
}
}

impl TryFrom<&StoreConfigType> for ReadableWritableListableStorage {
impl TryFrom<&StoreConfig> for ReadableWritableListableStorage {
type Error = PyErr;

fn try_from(value: &StoreConfigType) -> Result<Self, Self::Error> {
fn try_from(value: &StoreConfig) -> Result<Self, Self::Error> {
match value {
StoreConfigType::Filesystem(config) => config.try_into(),
StoreConfigType::Http(config) => config.try_into(),
StoreConfig::Filesystem(config) => config.try_into(),
StoreConfig::Http(config) => config.try_into(),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/store/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use zarrs::{filesystem::FilesystemStore, storage::ReadableWritableListableStorag

use crate::utils::PyErrExt;

use super::StoreConfig;

#[gen_stub_pyclass]
#[pyclass(extends=StoreConfig)]
#[pyclass]
pub struct FilesystemStoreConfig {
root: String,
}
Expand Down
4 changes: 2 additions & 2 deletions src/store/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use pyo3::{exceptions::PyValueError, pyclass, Bound, PyAny, PyErr, PyResult};
use pyo3_stub_gen::derive::gen_stub_pyclass;
use zarrs::storage::ReadableWritableListableStorage;

use super::{opendal_builder_to_sync_store, StoreConfig};
use super::opendal_builder_to_sync_store;

#[gen_stub_pyclass]
#[pyclass(extends=StoreConfig)]
#[pyclass]
pub struct HttpStoreConfig {
pub root: String,
}
Expand Down

0 comments on commit 78d9642

Please sign in to comment.