Skip to content

Commit f7bf483

Browse files
authored
Simplify impl of from_url for GCP and Azure (#235)
1 parent 5a84390 commit f7bf483

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

pyo3-object_store/src/azure.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl PyAzureStore {
122122
retry_config: Option<PyRetryConfig>,
123123
kwargs: Option<PyAzureConfig>,
124124
) -> PyObjectStoreResult<Self> {
125-
// We manually parse the URL to find the prefix because `with_url` does not apply the
125+
// We manually parse the URL to find the prefix because `parse_url` does not apply the
126126
// prefix.
127127
let (_, prefix) =
128128
ObjectStoreScheme::parse(url.as_ref()).map_err(object_store::Error::from)?;
@@ -131,27 +131,15 @@ impl PyAzureStore {
131131
} else {
132132
None
133133
};
134-
135134
let config = parse_url(config, url.as_ref())?;
136-
let mut builder = MicrosoftAzureBuilder::from_env().with_url(url.clone());
137-
let combined_config = combine_config_kwargs(Some(config), kwargs)?;
138-
builder = combined_config.clone().apply_config(builder);
139-
if let Some(client_options) = client_options.clone() {
140-
builder = builder.with_client_options(client_options.into())
141-
}
142-
if let Some(retry_config) = retry_config.clone() {
143-
builder = builder.with_retry(retry_config.into())
144-
}
145-
Ok(Self {
146-
store: Arc::new(MaybePrefixedStore::new(builder.build()?, prefix.clone())),
147-
config: AzureConfig {
148-
prefix,
149-
config: combined_config,
150-
client_options,
151-
retry_config,
152-
},
153-
})
154-
// Ok(Self(Arc::new(builder.build()?)))
135+
Self::new(
136+
None,
137+
prefix,
138+
Some(config),
139+
client_options,
140+
retry_config,
141+
kwargs,
142+
)
155143
}
156144

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

pyo3-object_store/src/gcp.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl PyGCSStore {
122122
retry_config: Option<PyRetryConfig>,
123123
kwargs: Option<PyGoogleConfig>,
124124
) -> PyObjectStoreResult<Self> {
125-
// We manually parse the URL to find the prefix because `with_url` does not apply the
125+
// We manually parse the URL to find the prefix because `parse_url` does not apply the
126126
// prefix.
127127
let (_, prefix) =
128128
ObjectStoreScheme::parse(url.as_ref()).map_err(object_store::Error::from)?;
@@ -132,24 +132,14 @@ impl PyGCSStore {
132132
None
133133
};
134134
let config = parse_url(config, url.as_ref())?;
135-
let mut builder = GoogleCloudStorageBuilder::from_env().with_url(url.clone());
136-
let combined_config = combine_config_kwargs(Some(config), kwargs)?;
137-
builder = combined_config.clone().apply_config(builder);
138-
if let Some(client_options) = client_options.clone() {
139-
builder = builder.with_client_options(client_options.into())
140-
}
141-
if let Some(retry_config) = retry_config.clone() {
142-
builder = builder.with_retry(retry_config.into())
143-
}
144-
Ok(Self {
145-
store: Arc::new(MaybePrefixedStore::new(builder.build()?, prefix.clone())),
146-
config: GCSConfig {
147-
prefix,
148-
config: combined_config,
149-
client_options,
150-
retry_config,
151-
},
152-
})
135+
Self::new(
136+
None,
137+
prefix,
138+
Some(config),
139+
client_options,
140+
retry_config,
141+
kwargs,
142+
)
153143
}
154144

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

0 commit comments

Comments
 (0)