diff --git a/lib/zip.js b/lib/zip.js index eba21976..a5a9a7fb 100644 --- a/lib/zip.js +++ b/lib/zip.js @@ -18,6 +18,11 @@ function addVendorHelper() { if (this.options.zip) { if (this.serverless.service.package.individually) { return BbPromise.resolve(values(this.serverless.service.functions)) + .filter(func => + (func.runtime || this.serverless.service.provider.runtime).match( + /^python.*/ + ) + ) .map(f => { if (!get(f, 'package.include')) { set(f, ['package', 'include'], []); @@ -64,6 +69,11 @@ function removeVendorHelper() { if (this.options.zip && this.options.cleanupZipHelper) { if (this.serverless.service.package.individually) { return BbPromise.resolve(values(this.serverless.service.functions)) + .filter(func => + (func.runtime || this.serverless.service.provider.runtime).match( + /^python.*/ + ) + ) .map(f => { if (!get(f, 'module')) { set(f, ['module'], '.'); @@ -96,6 +106,11 @@ function packRequirements() { if (this.options.zip) { if (this.serverless.service.package.individually) { return BbPromise.resolve(values(this.serverless.service.functions)) + .filter(f => + (f.runtime || this.serverless.service.provider.runtime).match( + /^python.*/ + ) + ) .map(f => { if (!get(f, 'module')) { set(f, ['module'], '.'); diff --git a/test.bats b/test.bats index 4501ba52..a5b68d11 100755 --- a/test.bats +++ b/test.bats @@ -376,6 +376,56 @@ teardown() { ! ls puck2/pyaml } +@test "py2.7 can package module requirements with zip option" { + cd tests/individually + npm i $(npm pack ../..) + sls --zip=true --runtime=python2.7 package + unzip .serverless/hello1.zip -d puck + unzip .serverless/hello2.zip -d puck2 + ls puck/.requirements.zip puck/unzip_requirements.py + ls puck2/.requirements.zip puck2/unzip_requirements.py +} + +@test "py3.6 can package module requirements with zip option" { + cd tests/individually + npm i $(npm pack ../..) + sls --zip=true package + unzip .serverless/hello1.zip -d puck + unzip .serverless/hello2.zip -d puck2 + ls puck/.requirements.zip puck/unzip_requirements.py + ls puck2/.requirements.zip puck2/unzip_requirements.py +} + +@test "py2.7 can package only python runtimes" { + cd tests/individually + npm i $(npm pack ../..) + sls --runtime=python2.7 package + unzip .serverless/module1-sls-py-req-test-indiv-dev-hello1.zip -d puck + unzip .serverless/module2-sls-py-req-test-indiv-dev-hello2.zip -d puck2 + unzip .serverless/hello3.zip -d puck3 + ls puck3/module3/handler3.js + ! ls puck/handler3.js + ! ls puck2/handler3.js + ! ls puck3/flask + ! ls puck3/pyaml +} + +@test "py2.7 can package only python runtimes with zip option" { + cd tests/individually + npm i $(npm pack ../..) + sls --zip=true --runtime=python2.7 package + unzip .serverless/hello3.zip -d puck3 + ! ls puck3/.requirements.zip puck3/unzip_requirements.py +} + +@test "py3.6 can package only python runtimes with zip option" { + cd tests/individually + npm i $(npm pack ../..) + sls --zip=true package + unzip .serverless/hello3.zip -d puck3 + ! ls puck3/.requirements.zip puck3/unzip_requirements.py +} + @test "py3.6 can package lambda-decorators using vendor option" { cd tests/base npm i $(npm pack ../..) diff --git a/tests/individually/module3/handler3.js b/tests/individually/module3/handler3.js new file mode 100644 index 00000000..d8694077 --- /dev/null +++ b/tests/individually/module3/handler3.js @@ -0,0 +1,3 @@ +exports.hello = function(event, context, callback) { + callback(null, { status: 200 }) +}; diff --git a/tests/individually/serverless.yml b/tests/individually/serverless.yml index 427dba75..23578e9a 100644 --- a/tests/individually/serverless.yml +++ b/tests/individually/serverless.yml @@ -2,11 +2,17 @@ service: sls-py-req-test-indiv provider: name: aws - runtime: python3.6 + runtime: ${opt:runtime, 'python3.6'} package: individually: true +custom: + pythonRequirements: + zip: ${opt:zip, self:custom.defaults.zip} + defaults: + zip: false + functions: hello1: handler: handler1.hello @@ -14,6 +20,14 @@ functions: hello2: handler: handler2.hello module: module2 + hello3: + handler: module3/handler3.hello + runtime: node6.10 + package: + exclude: + - '**/*' + include: + - 'module3/**/*' plugins: - serverless-python-requirements