diff --git a/README.md b/README.md index b3654f3..e2feefd 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Example lambda.json file: "handler": "function.lambda_handler", "role": "arn:aws:iam::00000000000:role/lambda_basic_execution", "requirements": ["pygithub"], + "ignore": ["circle.yml"], "timeout": 30, "memory": 512 } diff --git a/README.rst b/README.rst index db1a8b3..7d6c042 100644 --- a/README.rst +++ b/README.rst @@ -42,6 +42,7 @@ Example lambda.json file: "handler": "function.lambda_handler", "role": "arn:aws:iam::00000000000:role/lambda_basic_execution", "requirements": ["pygithub"], + "ignore": ["circle.yml"], "timeout": 30, "memory": 512 } diff --git a/example/circle.yml b/example/circle.yml new file mode 100644 index 0000000..8413a1f --- /dev/null +++ b/example/circle.yml @@ -0,0 +1,7 @@ +machine: + python: + version: 2.7 + +test: + override: + - flake8 . diff --git a/example/lambda.json b/example/lambda.json index a70968f..7148a5b 100644 --- a/example/lambda.json +++ b/example/lambda.json @@ -5,6 +5,7 @@ "handler": "function.lambda_handler", "role": "arn:aws:iam::00000000000:role/lambda_basic_execution", "requirements": ["Jinja2==2.8"], + "ignore": ["circle.yml"], "timeout": 30, "memory": 512 } diff --git a/lambda_uploader/config.py b/lambda_uploader/config.py index 048a528..3768dc6 100644 --- a/lambda_uploader/config.py +++ b/lambda_uploader/config.py @@ -15,12 +15,13 @@ import json from os import path -REQUIRED_PARAMS = {'name': basestring, 'description': basestring, - 'region': basestring, 'handler': basestring, - 'role': basestring, 'timeout': int, 'memory': int} +REQUIRED_PARAMS = {u'name': basestring, u'description': basestring, + u'region': basestring, u'handler': basestring, + u'role': basestring, u'timeout': int, u'memory': int} DEFAULT_PARAMS = {u'requirements': [], u'publish': False, - u'alias': None, u'alias_description': None} + u'alias': None, u'alias_description': None, + u'ignore': []} class Config(object): diff --git a/lambda_uploader/package.py b/lambda_uploader/package.py index 8bbbf54..1bb0089 100644 --- a/lambda_uploader/package.py +++ b/lambda_uploader/package.py @@ -26,7 +26,7 @@ ZIPFILE_NAME = 'lambda_function.zip' -def build_package(path, requirements, virtualenv=None): +def build_package(path, requirements, virtualenv=None, ignore=[]): pkg = Package(path, virtualenv) pkg.clean_workspace() @@ -40,7 +40,7 @@ def build_package(path, requirements, virtualenv=None): LOG.info('Building new virtualenv and installing requirements') pkg.prepare_virtualenv() pkg.install_requirements(requirements) - pkg.package() + pkg.package(ignore) return pkg @@ -103,7 +103,7 @@ def install_requirements(self, requirements): if prc.returncode is not 0: raise Exception('pip returned unsuccessfully') - def package(self): + def package(self, ignore=[]): package = os.path.join(self._temp_workspace, 'lambda_package') # Copy site packages into package base @@ -122,7 +122,9 @@ def package(self): LOG.info('Copying lib64 site packages') utils.copy_tree(lib64_path, package) - utils.copy_tree(self._path, package, ignore=[TEMP_WORKSPACE_NAME]) + # Append the temp workspace to the ignore list + ignore.append("^%s/*" % self._temp_workspace) + utils.copy_tree(self._path, package, ignore) self._create_zip(package) def _create_zip(self, src): diff --git a/lambda_uploader/shell.py b/lambda_uploader/shell.py index 5b57967..c36fe21 100644 --- a/lambda_uploader/shell.py +++ b/lambda_uploader/shell.py @@ -50,7 +50,8 @@ def _execute(args): cfg = config.Config(pth, args.config, role=args.role) _print('Building Package') - pkg = package.build_package(pth, cfg.requirements, args.virtualenv) + pkg = package.build_package(pth, cfg.requirements, + args.virtualenv, cfg.ignore) if not args.no_clean: pkg.clean_workspace() diff --git a/lambda_uploader/utils.py b/lambda_uploader/utils.py index 8538130..5ee0845 100644 --- a/lambda_uploader/utils.py +++ b/lambda_uploader/utils.py @@ -15,6 +15,7 @@ import os import shutil import logging +import re LOG = logging.getLogger(__name__) @@ -45,6 +46,6 @@ def _ignore_file(path, ignore=[]): if not ignore: return False for ign in ignore: - if ign in path: + if re.search(ign, path): return True return False diff --git a/test/test_utils.py b/test/test_utils.py index 1305e7e..216a233 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -11,9 +11,10 @@ 'bar/foo.py', 'bar/bar/foo.py', 'ignore/foo.py' + 'ignore-me.py' ] -TEST_IGNORE = ['ignore/'] +TEST_IGNORE = ['ignore/*', 'ignore-me.py'] def test_copy_tree():