@@ -279,10 +279,11 @@ def create_deployment(
279279DEPENDENCIES_ARCHIVE_PATH = os .path .join (
280280 "payload" , "archives" , DEPENDENCIES_ARCHIVE_FULL_NAME
281281)
282+ PY_FILES_PATH = os .path .join ("payload" , "py-files" )
282283ZIP_FILE_NAME = "deployment.zip"
283284
284285
285- def prepare_dependency_archive (directory : str , docker_network : str ) -> None :
286+ def prepare_dependency_archive (directory : str , docker_network : str , package_type : str ) -> None :
286287 cmd = f"docker images -q { DOCKER_IMAGE_NAME } "
287288 image_exists = cmd_output (cmd )
288289
@@ -299,11 +300,21 @@ def prepare_dependency_archive(directory: str, docker_network: str) -> None:
299300 shutil .copy ("build_native_dependencies.sh" , temp_dir )
300301 cmd = docker_run_cmd (docker_network , temp_dir )
301302 cmd_output (cmd )
302- archives_temp_path = os .path .join (temp_dir , DEPENDENCIES_ARCHIVE_FULL_NAME )
303- os .makedirs (os .path .dirname (DEPENDENCIES_ARCHIVE_PATH ), exist_ok = True )
304- shutil .copy (archives_temp_path , DEPENDENCIES_ARCHIVE_PATH )
305303
306- logger .info (f"Dependencies archived to { DEPENDENCIES_ARCHIVE_PATH } " )
304+ if package_type == "function" :
305+ source_py_files = os .path .join (temp_dir , "py-files" )
306+ os .makedirs (os .path .dirname (PY_FILES_PATH ), exist_ok = True )
307+ if os .path .exists (PY_FILES_PATH ):
308+ shutil .rmtree (PY_FILES_PATH )
309+ shutil .copytree (source_py_files , PY_FILES_PATH )
310+ logger .info (f"Dependencies copied to { PY_FILES_PATH } " )
311+ else :
312+ archives_temp_path = os .path .join (
313+ temp_dir , DEPENDENCIES_ARCHIVE_FULL_NAME
314+ )
315+ os .makedirs (os .path .dirname (DEPENDENCIES_ARCHIVE_PATH ), exist_ok = True )
316+ shutil .copy (archives_temp_path , DEPENDENCIES_ARCHIVE_PATH )
317+ logger .info (f"Dependencies archived to { DEPENDENCIES_ARCHIVE_PATH } " )
307318
308319
309320def docker_build_cmd (network : str ) -> str :
@@ -511,16 +522,28 @@ def upload_zip(file_upload_url: str) -> None:
511522 response .raise_for_status ()
512523
513524
525+ def _get_package_type_for_directory (directory : str ) -> str :
526+ """Resolve package type (script/function) for the given payload directory."""
527+ try :
528+ entrypoint_path = os .path .join (os .path .abspath (directory ), "entrypoint.py" )
529+ base_directory = find_base_directory (entrypoint_path )
530+ return get_package_type (base_directory )
531+ except (ValueError , FileNotFoundError ):
532+ return "script"
533+
534+
514535def zip (
515536 directory : str ,
516537 docker_network : str ,
517538):
518539 # Create a zip file excluding .DS_Store files
519540 import zipfile
520541
542+ package_type = _get_package_type_for_directory (directory )
543+
521544 # prepare payload only if requirements.txt is non-empty
522545 if has_nonempty_requirements_file (directory ):
523- prepare_dependency_archive (directory , docker_network )
546+ prepare_dependency_archive (directory , docker_network , package_type )
524547 else :
525548 logger .info (
526549 f"Skipping dependency archive: requirements.txt is missing or empty "
0 commit comments