Skip to content

Commit b016ca8

Browse files
authored
Merge pull request #11 from saturncloud/bugfix/s3anon
Fixing the anon thing in list_all_files
2 parents 9e6bed7 + a96fef5 commit b016ca8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

dask_pytorch_ddp/data.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
""" # pylint: disable=pointless-string-statement
1919

2020

21-
def _list_all_files(bucket: str, prefix: str, s3_client=None) -> List[str]:
21+
def _list_all_files(bucket: str, prefix: str, s3_client=None, anon=False) -> List[str]:
2222
"""
2323
Get list of all files from an s3 bucket matching a certain prefix
2424
"""
2525
import boto3 # pylint: disable=import-outside-toplevel
26+
from botocore import UNSIGNED # pylint: disable=import-outside-toplevel
27+
from botocore.client import Config # pylint: disable=import-outside-toplevel
2628

2729
if s3_client is None:
28-
s3_client = boto3.client("s3")
30+
if anon:
31+
s3_client = boto3.client("s3", config=Config(signature_version=UNSIGNED))
32+
else:
33+
s3_client = boto3.client("s3")
34+
2935
paginator = s3_client.get_paginator("list_objects")
3036
all_files = []
3137
for page in paginator.paginate(Bucket=bucket, Prefix=prefix):
@@ -78,12 +84,12 @@ def __init__(
7884
):
7985
self.s3_bucket = s3_bucket
8086
self.s3_prefix = s3_prefix
81-
self.all_files = _list_all_files(s3_bucket, s3_prefix)
87+
self.anon = anon
88+
self.all_files = _list_all_files(s3_bucket, s3_prefix, anon)
8289
self.classes = sorted({self._get_class(x) for x in self.all_files})
8390
self.class_to_idx = {k: idx for idx, k in enumerate(self.classes)}
8491
self.transform = transform
8592
self.target_transform = target_transform
86-
self.anon = anon
8793

8894
@classmethod
8995
def _get_class(cls, path):

0 commit comments

Comments
 (0)