1717import  zipfile 
1818import  logging 
1919import  sys 
20+ import  re 
2021
2122from  subprocess  import  Popen , PIPE 
2223from  lambda_uploader  import  utils 
2324from  distutils .spawn  import  find_executable 
2425
25- # Python 2/3 compatability  
26+ # Python 2/3 compatibility  
2627try :
2728    basestring 
2829except  NameError :
3435ZIPFILE_NAME  =  'lambda_function.zip' 
3536
3637
37- def  build_package (path , requires , virtualenv = None , ignore = [] ,
38-                   extra_files = [] , zipfile_name = ZIPFILE_NAME ):
38+ def  build_package (path , requires , virtualenv = None , ignore = None ,
39+                   extra_files = None , zipfile_name = ZIPFILE_NAME ):
3940    '''Builds the zip file and creates the package with it''' 
4041    pkg  =  Package (path , zipfile_name )
4142
@@ -69,7 +70,7 @@ def __init__(self, path, zipfile_name=ZIPFILE_NAME):
6970        self ._requirements_file  =  os .path .join (self ._path , "requirements.txt" )
7071        self ._extra_files  =  []
7172
72-     def  build (self , ignore = [] ):
73+     def  build (self , ignore = None ):
7374        '''Calls all necessary methods to build the Lambda Package''' 
7475        self ._prepare_workspace ()
7576        self .install_dependencies ()
@@ -214,7 +215,7 @@ def _install_requirements(self):
214215            if  prc .returncode  is  not   0 :
215216                raise  Exception ('pip returned unsuccessfully' )
216217
217-     def  package (self , ignore = [] ):
218+     def  package (self , ignore = None ):
218219        """ 
219220        Create a zip file of the lambda script and its dependencies. 
220221
@@ -223,6 +224,7 @@ def package(self, ignore=[]):
223224            those files when creating the zip file. The paths to be matched are 
224225            local to the source root. 
225226        """ 
227+         ignore  =  ignore  or  []
226228        package  =  os .path .join (self ._temp_workspace , 'lambda_package' )
227229
228230        # Copy site packages into package base 
@@ -243,13 +245,13 @@ def package(self, ignore=[]):
243245                utils .copy_tree (lib64_path , package )
244246
245247        # Append the temp workspace to the ignore list: 
246-         ignore   +=  [ "^%s/*"  %  TEMP_WORKSPACE_NAME ] 
248+         ignore . append ( r "^%s/. *"  %  re . escape ( TEMP_WORKSPACE_NAME )) 
247249        utils .copy_tree (self ._path , package , ignore )
248250
249251        # Add extra files 
250252        for  p  in  self ._extra_files :
251253            LOG .info ('Copying extra %s into package'  %  p )
252-             ignore   +=  [ "%s"   %   p ] 
254+             ignore . append ( re . escape ( p )) 
253255            if  os .path .isdir (p ):
254256                utils .copy_tree (p , package , ignore = ignore , include_parent = True )
255257            else :
0 commit comments