Skip to content

Commit

Permalink
Simplify impl of from_url for GCP and Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Feb 7, 2025
1 parent 5a84390 commit 86b3429
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 40 deletions.
30 changes: 9 additions & 21 deletions pyo3-object_store/src/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl PyAzureStore {
retry_config: Option<PyRetryConfig>,
kwargs: Option<PyAzureConfig>,
) -> PyObjectStoreResult<Self> {
// We manually parse the URL to find the prefix because `with_url` does not apply the
// We manually parse the URL to find the prefix because `parse_url` does not apply the
// prefix.
let (_, prefix) =
ObjectStoreScheme::parse(url.as_ref()).map_err(object_store::Error::from)?;
Expand All @@ -131,27 +131,15 @@ impl PyAzureStore {
} else {
None
};

let config = parse_url(config, url.as_ref())?;
let mut builder = MicrosoftAzureBuilder::from_env().with_url(url.clone());
let combined_config = combine_config_kwargs(Some(config), kwargs)?;
builder = combined_config.clone().apply_config(builder);
if let Some(client_options) = client_options.clone() {
builder = builder.with_client_options(client_options.into())
}
if let Some(retry_config) = retry_config.clone() {
builder = builder.with_retry(retry_config.into())
}
Ok(Self {
store: Arc::new(MaybePrefixedStore::new(builder.build()?, prefix.clone())),
config: AzureConfig {
prefix,
config: combined_config,
client_options,
retry_config,
},
})
// Ok(Self(Arc::new(builder.build()?)))
Self::new(
None,
prefix,
Some(config),
client_options,
retry_config,
kwargs,
)
}

fn __getnewargs_ex__(&self, py: Python) -> PyResult<PyObject> {
Expand Down
28 changes: 9 additions & 19 deletions pyo3-object_store/src/gcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl PyGCSStore {
retry_config: Option<PyRetryConfig>,
kwargs: Option<PyGoogleConfig>,
) -> PyObjectStoreResult<Self> {
// We manually parse the URL to find the prefix because `with_url` does not apply the
// We manually parse the URL to find the prefix because `parse_url` does not apply the
// prefix.
let (_, prefix) =
ObjectStoreScheme::parse(url.as_ref()).map_err(object_store::Error::from)?;
Expand All @@ -132,24 +132,14 @@ impl PyGCSStore {
None
};
let config = parse_url(config, url.as_ref())?;
let mut builder = GoogleCloudStorageBuilder::from_env().with_url(url.clone());
let combined_config = combine_config_kwargs(Some(config), kwargs)?;
builder = combined_config.clone().apply_config(builder);
if let Some(client_options) = client_options.clone() {
builder = builder.with_client_options(client_options.into())
}
if let Some(retry_config) = retry_config.clone() {
builder = builder.with_retry(retry_config.into())
}
Ok(Self {
store: Arc::new(MaybePrefixedStore::new(builder.build()?, prefix.clone())),
config: GCSConfig {
prefix,
config: combined_config,
client_options,
retry_config,
},
})
Self::new(
None,
prefix,
Some(config),
client_options,
retry_config,
kwargs,
)
}

fn __getnewargs_ex__(&self, py: Python) -> PyResult<PyObject> {
Expand Down

0 comments on commit 86b3429

Please sign in to comment.