@@ -177,35 +177,6 @@ def prepare_dependency_archive(directory: str) -> None:
177
177
logger .debug (f"Dependencies downloaded and archived to { archive_file } " )
178
178
179
179
180
- def zip_and_upload_directory (directory : str , name : str ) -> None :
181
- # file_upload_url = unescape(file_upload_url)
182
-
183
- logger .debug (f"Zipping directory... { directory } " )
184
-
185
- # Create a zip file excluding .DS_Store files
186
- import zipfile
187
-
188
- zip_filename = f"{ name } .zip"
189
- with zipfile .ZipFile (zip_filename , 'w' , zipfile .ZIP_DEFLATED ) as zipf :
190
- for root , dirs , files in os .walk (directory ):
191
- # Skip .DS_Store files when adding to zip
192
- for file in files :
193
- if file != '.DS_Store' :
194
- file_path = os .path .join (root , file )
195
- # Preserve relative path structure in the zip file
196
- arcname = os .path .relpath (file_path , directory )
197
- zipf .write (file_path , arcname )
198
-
199
- logger .debug (f"Created zip file: { zip_filename } (excluding .DS_Store files)" )
200
-
201
- # logger.debug(f"Uploading deployment to {file_upload_url}")
202
- # with open(ZIP_FILE_NAME, "rb") as zip_file:
203
- # response = requests.put(
204
- # file_upload_url, data=zip_file, headers={"Content-Type": "application/zip"}
205
- # )
206
- # response.raise_for_status()
207
-
208
-
209
180
class DeploymentsResponse (BaseModel ):
210
181
deploymentStatus : str
211
182
@@ -342,59 +313,70 @@ def create_data_transform(
342
313
response = _make_api_call (url , "POST" , token = access_token .access_token , json = body )
343
314
return response
344
315
316
+
345
317
def has_nonempty_requirements_file (directory : str ) -> bool :
346
318
"""
347
- Check if requirements.txt exists in the given directory and has at least one non-comment line.
319
+ Check if requirements.txt exists in the given directory and has at least
320
+ one non-comment line.
348
321
Args:
349
322
directory (str): The directory to check for requirements.txt.
350
323
Returns:
351
- bool: True if requirements.txt exists and has a non-comment line, False otherwise.
324
+ bool: True if requirements.txt exists and has a non-comment line,
325
+ False otherwise.
352
326
"""
353
327
# Look for requirements.txt in the parent directory of the given directory
354
328
requirements_path = os .path .join (os .path .dirname (directory ), "requirements.txt" )
355
- print (requirements_path )
356
329
357
330
try :
358
331
if os .path .isfile (requirements_path ):
359
- #print the contents of the file
360
- with open (requirements_path , "r" , encoding = "utf-8" ) as f :
361
- print (f .read ())
362
332
with open (requirements_path , "r" , encoding = "utf-8" ) as f :
363
333
for line in f :
364
- # Consider non-empty if any line is not a comment (ignoring leading whitespace)
365
- if line .strip () and not line .lstrip ().startswith ('#' ):
334
+ # Consider non-empty if any line is not a comment (ignoring
335
+ # leading whitespace)
336
+ if line .strip () and not line .lstrip ().startswith ("#" ):
366
337
return True
367
338
except Exception as e :
368
339
logger .error (f"Error reading requirements.txt: { e } " )
369
340
return False
370
341
371
342
343
+ def upload_zip (file_upload_url : str ) -> None :
344
+ file_upload_url = unescape (file_upload_url )
345
+ with open (ZIP_FILE_NAME , "rb" ) as zip_file :
346
+ response = requests .put (
347
+ file_upload_url , data = zip_file , headers = {"Content-Type" : "application/zip" }
348
+ )
349
+ response .raise_for_status ()
350
+
351
+
372
352
def zip (
373
353
directory : str ,
374
- metadata : TransformationJobMetadata ,
375
- credentials : Credentials ,
376
- name : str ,
377
- callback = None ,
378
- ) -> AccessTokenResponse :
379
- """Deploy a data transform in the DataCloud."""
380
- access_token = _retrieve_access_token (credentials )
354
+ ):
355
+ # Create a zip file excluding .DS_Store files
356
+ import zipfile
381
357
382
358
# prepare payload only if requirements.txt is non-empty
383
359
if has_nonempty_requirements_file (directory ):
384
360
prepare_dependency_archive (directory )
385
361
else :
386
- logger .info (f"Skipping dependency archive: requirements.txt is missing or empty in { directory } " )
387
- # create_data_transform_config(directory)
362
+ logger .info (
363
+ f"Skipping dependency archive: requirements.txt is missing or empty "
364
+ f"in { directory } "
365
+ )
388
366
389
- # create deployment and upload payload
390
- # deployment = create_deployment(access_token, metadata)
391
- zip_and_upload_directory (directory , name )
392
- #, deployment.fileUploadUrl)
393
- # wait_for_deployment(access_token, metadata, callback)
367
+ logger .debug (f"Zipping directory... { directory } " )
394
368
395
- # create data transform
396
- # create_data_transform(directory, access_token, metadata)
397
- return access_token
369
+ with zipfile .ZipFile (ZIP_FILE_NAME , "w" , zipfile .ZIP_DEFLATED ) as zipf :
370
+ for root , dirs , files in os .walk (directory ):
371
+ # Skip .DS_Store files when adding to zip
372
+ for file in files :
373
+ if file != ".DS_Store" :
374
+ file_path = os .path .join (root , file )
375
+ # Preserve relative path structure in the zip file
376
+ arcname = os .path .relpath (file_path , directory )
377
+ zipf .write (file_path , arcname )
378
+
379
+ logger .debug (f"Created zip file: { ZIP_FILE_NAME } " )
398
380
399
381
400
382
def deploy_full (
@@ -412,7 +394,8 @@ def deploy_full(
412
394
413
395
# create deployment and upload payload
414
396
deployment = create_deployment (access_token , metadata )
415
- zip_and_upload_directory (directory , deployment .fileUploadUrl )
397
+ zip (directory )
398
+ upload_zip (deployment .fileUploadUrl )
416
399
wait_for_deployment (access_token , metadata , callback )
417
400
418
401
# create data transform
0 commit comments