Skip to content

Commit

Permalink
feat: Do not zip req for non-py functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stijn IJzermans committed Jan 10, 2024
1 parent b69566f commit df71858
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ function packRequirements() {
if (this.options.zip) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.filter((func) => {
return (
func.runtime || this.serverless.service.provider.runtime
).match(/^python.*/);
})
.map((f) => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
Expand Down
14 changes: 9 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ test(
const path = npm(['pack', '../..']);

npm(['i', path]);
sls(['package'], { env: { dockerizePip: 'true' } });
sls(['package'], { env: { dockerizePip: 'true', zip: 'true' } });

const zipfiles_hello = await listZipFiles('.serverless/hello1.zip');
t.true(
Expand All @@ -1427,31 +1427,35 @@ test(
const zipfiles_hello2 = await listZipFiles(
'.serverless/module2-sls-py-req-test-indiv-mixed-dev-hello2.zip'
);
const zippedReqs = await listRequirementsZipFiles(
'.serverless/module2-sls-py-req-test-indiv-mixed-dev-hello2.zip'
);
t.true(
zipfiles_hello2.includes('handler2.py'),
'handler2.py is packaged at root level in function hello2'
);
t.false(
zipfiles_hello2.includes(`module1${sep}handler1.ts`),
'handler1.py is NOT incldued at module1 level in hello2'
'handler1.ts is NOT included at module1 level in hello2'
);
t.false(
zipfiles_hello2.includes(`pyaml${sep}__init__.py`),
'pyaml is NOT packaged in function hello2'
);
t.false(
zipfiles_hello2.includes(`boto3${sep}__init__.py`),
'boto3 is NOT packaged in function hello2'
'boto3 is NOT included in zipfile'
);
t.true(
zipfiles_hello2.includes(`flask${sep}__init__.py`),
'flask is packaged in function hello2'
zippedReqs.includes(`flask${sep}__init__.py`),
'flask is packaged in function hello2 in requirements.zip'
);

t.end();
},
{ skip: !canUseDocker() || process.platform === 'win32' }
);

test(
'py3.9 uses download cache by default option',
async (t) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/individually_mixed/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ package:
custom:
pythonRequirements:
dockerizePip: ${env:dockerizePip, self:custom.defaults.dockerizePip}
zip: ${env:zip, self:custom.defaults.zip}
defaults:
dockerizePip: false
zip: false

functions:
hello1:
handler: handler1.hello
architecture: x86_64
package:
patterns:
- '!**'
Expand Down

0 comments on commit df71858

Please sign in to comment.