17
17
import zipfile
18
18
import logging
19
19
import sys
20
+ import re
20
21
21
22
from subprocess import Popen , PIPE
22
23
from lambda_uploader import utils
23
24
from distutils .spawn import find_executable
24
25
25
- # Python 2/3 compatability
26
+ # Python 2/3 compatibility
26
27
try :
27
28
basestring
28
29
except NameError :
34
35
ZIPFILE_NAME = 'lambda_function.zip'
35
36
36
37
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 ):
39
40
'''Builds the zip file and creates the package with it'''
40
41
pkg = Package (path , zipfile_name )
41
42
@@ -69,7 +70,7 @@ def __init__(self, path, zipfile_name=ZIPFILE_NAME):
69
70
self ._requirements_file = os .path .join (self ._path , "requirements.txt" )
70
71
self ._extra_files = []
71
72
72
- def build (self , ignore = [] ):
73
+ def build (self , ignore = None ):
73
74
'''Calls all necessary methods to build the Lambda Package'''
74
75
self ._prepare_workspace ()
75
76
self .install_dependencies ()
@@ -214,7 +215,7 @@ def _install_requirements(self):
214
215
if prc .returncode is not 0 :
215
216
raise Exception ('pip returned unsuccessfully' )
216
217
217
- def package (self , ignore = [] ):
218
+ def package (self , ignore = None ):
218
219
"""
219
220
Create a zip file of the lambda script and its dependencies.
220
221
@@ -223,6 +224,7 @@ def package(self, ignore=[]):
223
224
those files when creating the zip file. The paths to be matched are
224
225
local to the source root.
225
226
"""
227
+ ignore = ignore or []
226
228
package = os .path .join (self ._temp_workspace , 'lambda_package' )
227
229
228
230
# Copy site packages into package base
@@ -243,13 +245,13 @@ def package(self, ignore=[]):
243
245
utils .copy_tree (lib64_path , package )
244
246
245
247
# Append the temp workspace to the ignore list:
246
- ignore += [ "^%s/*" % TEMP_WORKSPACE_NAME ]
248
+ ignore . append ( r "^%s/. *" % re . escape ( TEMP_WORKSPACE_NAME ))
247
249
utils .copy_tree (self ._path , package , ignore )
248
250
249
251
# Add extra files
250
252
for p in self ._extra_files :
251
253
LOG .info ('Copying extra %s into package' % p )
252
- ignore += [ "%s" % p ]
254
+ ignore . append ( re . escape ( p ))
253
255
if os .path .isdir (p ):
254
256
utils .copy_tree (p , package , ignore = ignore , include_parent = True )
255
257
else :
0 commit comments