Skip to content

Commit aae053a

Browse files
authoredMar 12, 2025··
fix: location constraint for default region (#44)
Fixes failure where LocationConstraint is not accepted when region is us-east-1 (default) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Automatically applies the "us-east-1" region when no region is specified, ensuring a consistent default configuration. - **Refactor** - Simplified the bucket creation process by streamlining how the region is handled, resulting in improved consistency when interacting with storage services. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a3b61ad commit aae053a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎snakemake_storage_plugin_s3/__init__.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
)
2828
from snakemake_interface_storage_plugins.common import Operation
2929

30+
DEFAULT_REGION = "us-east-1"
31+
3032

3133
# Optional:
3234
# Define settings for your storage plugin (e.g. host url, credentials).
@@ -58,7 +60,7 @@ class StorageProviderSettings(StorageProviderSettingsBase):
5860
},
5961
)
6062
region: Optional[str] = field(
61-
default=None,
63+
default=DEFAULT_REGION,
6264
metadata={
6365
"help": "region constraint for the S3 storage",
6466
"env_var": True,
@@ -325,12 +327,12 @@ def store_object(self):
325327
# Ensure that the object is stored at the location specified by
326328
# self.local_path().
327329
if not self.bucket_exists():
328-
location_config = {}
329-
if self.provider.settings.region is not None:
330-
location_config = {"LocationConstraint": self.provider.settings.region}
331-
self.provider.s3c.create_bucket(
332-
Bucket=self.bucket, CreateBucketConfiguration=location_config
333-
)
330+
create_bucket_params = {"Bucket": self.bucket}
331+
if self.provider.settings.region != DEFAULT_REGION:
332+
create_bucket_params["CreateBucketConfiguration"] = {
333+
"LocationConstraint": self.provider.settings.region
334+
}
335+
self.provider.s3c.create_bucket(**create_bucket_params)
334336

335337
if self.local_path().is_dir():
336338
self._is_dir = True

0 commit comments

Comments
 (0)
Please sign in to comment.