1818import yaml
1919
2020from ..features .cname import CName
21- from ..logger import LoggerSetup
2221from .bucket import Bucket
2322
2423
@@ -53,7 +52,7 @@ def __init__(
5352 :since: 0.8.0
5453 """
5554
56- self ._bucket = Bucket (bucket_name , endpoint_url , s3_resource_config )
55+ self ._bucket = Bucket (bucket_name , endpoint_url , s3_resource_config , logger )
5756
5857 @property
5958 def bucket (self ):
@@ -68,8 +67,8 @@ def bucket(self):
6867
6968 def download_to_directory (
7069 self ,
71- cname ,
72- artifacts_dir ,
70+ cname : str ,
71+ artifacts_dir : str | PathLike [ str ] ,
7372 ):
7473 """
7574 Download S3 artifacts to a given directory.
@@ -80,8 +79,7 @@ def download_to_directory(
8079 :since: 0.8.0
8180 """
8281
83- if not isinstance (artifacts_dir , PathLike ):
84- artifacts_dir = Path (artifacts_dir )
82+ artifacts_dir = Path (artifacts_dir )
8583
8684 if not artifacts_dir .is_dir ():
8785 raise RuntimeError (f"Artifacts directory given is invalid: { artifacts_dir } " )
@@ -101,8 +99,8 @@ def download_to_directory(
10199
102100 def upload_from_directory (
103101 self ,
104- cname ,
105- artifacts_dir ,
102+ cname : str ,
103+ artifacts_dir : str | PathLike [ str ] ,
106104 delete_before_push = False ,
107105 ):
108106 """
@@ -115,8 +113,7 @@ def upload_from_directory(
115113 :since: 0.8.0
116114 """
117115
118- if not isinstance (artifacts_dir , PathLike ):
119- artifacts_dir = Path (artifacts_dir )
116+ artifacts_dir = Path (artifacts_dir )
120117
121118 cname_object = CName (cname )
122119
@@ -192,22 +189,34 @@ def upload_from_directory(
192189 "paths" : [],
193190 }
194191
192+ # Catch any invalid artifacts
193+ bad_files = [
194+ f
195+ for f in artifacts_dir .iterdir ()
196+ if not f .name .startswith (cname )
197+ and f .suffix not in [".release" , ".requirements" ]
198+ ]
199+ if bad_files :
200+ raise RuntimeError (
201+ f"Artifact name '{ bad_files [0 ].name } ' does not start with cname '{ cname } '"
202+ )
203+
195204 for artifact in artifacts_dir .iterdir ():
196205 if not artifact .match (f"{ cname } *" ):
197206 continue
198207
208+ if not artifact .name .startswith (cname ):
209+ raise RuntimeError (
210+ f"Artifact name '{ artifact .name } ' does not start with cname '{ cname } '"
211+ )
212+
199213 s3_key = f"objects/{ cname } /{ artifact .name } "
200214
201215 with artifact .open ("rb" ) as fp :
202216 md5sum = file_digest (fp , "md5" ).hexdigest ()
203217 sha256sum = file_digest (fp , "sha256" ).hexdigest ()
204218
205- if artifact .name .startswith (cname ):
206- suffix = artifact .name [len (cname ) :]
207- else :
208- raise RuntimeError (
209- f"Artifact name '{ artifact .name } ' does not start with cname '{ cname } '"
210- )
219+ suffix = artifact .name [len (cname ) :]
211220
212221 artifact_metadata = {
213222 "name" : artifact .name ,
0 commit comments