-
Notifications
You must be signed in to change notification settings - Fork 29
Add top-level from_url function
#179
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
67ef9ab
Add top-level `new_store` function
kylebarron 364b35a
comment
kylebarron c627925
Switch on object store scheme before extracting
kylebarron b42a22a
update docstring
kylebarron 0237e12
Merge in main
kylebarron 2827c11
Merge config and kwargs in `new_store`
kylebarron 3b013d3
More concise code
kylebarron d2ff37b
Add tests for `new_store`
kylebarron 67c0790
Merge branch 'main' into kyle/top-level-new-store
kylebarron cd8d517
Update links
kylebarron 90afcac
add to ocs
kylebarron 043dcd9
Construct stores directly instead via from_url
kylebarron ce05b54
Reuse PyUrl once
kylebarron 2d6fdce
Merge branch 'main' into kyle/top-level-new-store
kylebarron 7a877ae
Add `client_options` and `retry_config`
kylebarron b4f5303
Rename `new_store` to `from_url`
kylebarron 64666bc
Add note to docstring
kylebarron 88bc01f
Merge branch 'main' into kyle/top-level-new-store
kylebarron 1bba091
Minor compile fixes
kylebarron b4f2d1d
fix tests
kylebarron e2f354a
Don't look for file in localstore test
kylebarron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| # ObjectStore | ||
|
|
||
| ::: obstore.store.new_store | ||
| ::: obstore.store.ObjectStore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use object_store::memory::InMemory; | ||
| use object_store::ObjectStoreScheme; | ||
| use pyo3::prelude::*; | ||
| use pyo3::types::PyType; | ||
| use pyo3::IntoPyObjectExt; | ||
|
|
||
| use crate::error::ObstoreError; | ||
| use crate::url::PyUrl; | ||
| use crate::{ | ||
| PyAzureStore, PyGCSStore, PyHttpStore, PyLocalStore, PyMemoryStore, PyObjectStoreResult, | ||
| PyS3Store, | ||
| }; | ||
|
|
||
| /// Simple construction of stores by url. | ||
| // Note: We don't extract the PyObject in the function signature because it's possible that | ||
| // AWS/Azure/Google config keys could overlap. And so we don't want to accidentally parse a config | ||
| // as an AWS config before knowing that the URL scheme is AWS. | ||
| #[pyfunction] | ||
| #[pyo3(signature = (url, *, config=None, **kwargs))] | ||
| pub fn new_store( | ||
| py: Python, | ||
| url: PyUrl, | ||
| config: Option<Bound<PyAny>>, | ||
| kwargs: Option<Bound<PyAny>>, | ||
| ) -> PyObjectStoreResult<PyObject> { | ||
| let url = url.into_inner(); | ||
| let (scheme, _) = ObjectStoreScheme::parse(&url).map_err(object_store::Error::from)?; | ||
| match scheme { | ||
| ObjectStoreScheme::AmazonS3 => { | ||
| let store = PyS3Store::from_url( | ||
| &PyType::new::<PyS3Store>(py), | ||
| url.as_str(), | ||
| config.map(|x| x.extract()).transpose()?, | ||
| None, | ||
| None, | ||
| kwargs.map(|x| x.extract()).transpose()?, | ||
| )?; | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| ObjectStoreScheme::GoogleCloudStorage => { | ||
| let store = PyGCSStore::from_url( | ||
| &PyType::new::<PyGCSStore>(py), | ||
| url.as_str(), | ||
| config.map(|x| x.extract()).transpose()?, | ||
| None, | ||
| None, | ||
| kwargs.map(|x| x.extract()).transpose()?, | ||
| )?; | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| ObjectStoreScheme::MicrosoftAzure => { | ||
| let store = PyAzureStore::from_url( | ||
| &PyType::new::<PyAzureStore>(py), | ||
| url.as_str(), | ||
| config.map(|x| x.extract()).transpose()?, | ||
| None, | ||
| None, | ||
| kwargs.map(|x| x.extract()).transpose()?, | ||
| )?; | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| ObjectStoreScheme::Http => { | ||
| raise_if_config_passed(config, kwargs, "http")?; | ||
| let store = | ||
| PyHttpStore::from_url(&PyType::new::<PyHttpStore>(py), url.as_str(), None, None)?; | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| ObjectStoreScheme::Local => { | ||
| raise_if_config_passed(config, kwargs, "local")?; | ||
| let store = PyLocalStore::from_url(&PyType::new::<PyLocalStore>(py), url.as_str())?; | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| ObjectStoreScheme::Memory => { | ||
| raise_if_config_passed(config, kwargs, "memory")?; | ||
| let store: PyMemoryStore = Arc::new(InMemory::new()).into(); | ||
| Ok(store.into_pyobject(py)?.into_py_any(py)?) | ||
| } | ||
| scheme => { | ||
| return Err(ObstoreError::new_err(format!("Unknown URL scheme {:?}", scheme,)).into()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn raise_if_config_passed( | ||
| config: Option<Bound<PyAny>>, | ||
| kwargs: Option<Bound<PyAny>>, | ||
| scheme: &str, | ||
| ) -> PyObjectStoreResult<()> { | ||
| if config.is_some() || kwargs.is_some() { | ||
| return Err(ObstoreError::new_err(format!( | ||
| "Cannot pass config or keyword parameters for scheme {:?}", | ||
| scheme, | ||
| )) | ||
| .into()); | ||
| } | ||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.