99class Packager :
1010 AWS_LAMBDA_MAX_UNZIP_SIZE = 262144000
1111
12- def __init__ (self , venv_path : Path , project_path : Path , output_path : Path ):
12+ def __init__ (self , venv_path : Path , project_path : Path , output_dir : Path , output_file : Path | None ):
1313 self .project = PythonProject (project_path )
1414 self .venv_path = venv_path
15- self .output_path = output_path
16- self ._uncompressed_bytes = 0
1715
18- @property
19- def output_file_path (self ) -> Path :
20- if self .output_path .is_dir ():
21- return self .output_path / f'{ self .project .name } .zip'
22- return self .output_path
16+ self .output_dir = output_file .parent if output_file else output_dir
17+ self .output_file = output_file if output_file else output_dir / f'{ self .project .name } .zip'
18+
19+ self ._uncompressed_bytes = 0
2320
2421 @property
2522 def input_path (self ) -> Path :
@@ -30,11 +27,11 @@ def input_path(self) -> Path:
3027
3128 def package (self ) -> None :
3229 print ("Packaging:" , self .project .path )
33- print ("Output:" , self .output_file_path )
30+ print ("Output:" , self .output_file )
3431 print ("Input:" , self .input_path )
3532 print ("Entrypoint Package name:" , self .project .entrypoint_package_name )
3633
37- self .output_file_path . parent .mkdir (parents = True , exist_ok = True )
34+ self .output_dir .mkdir (parents = True , exist_ok = True )
3835
3936 with NamedTemporaryFile () as dependencies_zip :
4037 self .zip_all_dependencies (Path (dependencies_zip .name ))
@@ -66,10 +63,10 @@ def zip_dir(path: Path) -> None:
6663 else :
6764 print (f"TODO Error. The unzipped size it too large for AWS Lambda." )
6865 else :
69- shutil .copy (str (target_path ), str (self .output_file_path ))
66+ shutil .copy (str (target_path ), str (self .output_file ))
7067
7168 def generate_nested_zip (self , inner_zip_path : Path ) -> None :
72- with zipfile .ZipFile (self .output_file_path , 'w' ) as outer_zip_file :
69+ with zipfile .ZipFile (self .output_file , 'w' ) as outer_zip_file :
7370 entrypoint_dir = Path (self .project .entrypoint_package_name )
7471 outer_zip_file .write (
7572 inner_zip_path ,
0 commit comments