Skip to content

Commit

Permalink
fix: Not crash when runtime is not python (#773)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Kleinlein <m.kleinlein@enbw.com>
  • Loading branch information
jameskbride and mklenbw authored Aug 17, 2023
1 parent ad40278 commit c1f5ca1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ unzip_requirements.py
# Project ignores
puck/
serverless.yml.bak

# Generated packaging
*.tgz
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@ Welcome, and thanks in advance for your help!

## Setup

It is recommended to use Node v14 or v16 for development.

Then, to begin development fork repository and run `npm install` in its root folder.
Pre-Reqs:
* Python 3.7
* [poetry](https://python-poetry.org/docs/) (if you use multiple versions of Python be sure to install it with python 3.7)
* Perl (used in the tests)
* Node v14 or v16

Then, to begin development:
1. fork the repository
2. `npm install -g serverless@<VERSION>` (check the peer dependencies in the root `package.json` file for the version)
3. run `npm install` in its root folder
4. run the tests via `npm run test`

## Getting started

Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class ServerlessPythonRequirements {
this.serverless.service.custom.pythonRequirements) ||
{}
);
if (
options.pythonBin === this.serverless.service.provider.runtime &&
!options.pythonBin.startsWith('python')
) {
options.pythonBin = 'python';
}

if (options.dockerizePip === 'non-linux') {
options.dockerizePip = process.platform !== 'linux';
}
Expand Down
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,18 @@ test('poetry py3.7 fails packaging if poetry.lock is missing and flag requirePoe
t.end();
});

test('works with provider.runtime not being python', async (t) => {
process.chdir('tests/base');
const path = npm(['pack', '../..']);
npm(['i', path]);
sls(['package'], { env: { runtime: 'nodejs12.x' } });
t.true(
pathExistsSync('.serverless/sls-py-req-test.zip'),
'sls-py-req-test is packaged'
);
t.end();
});

test('poetry py3.7 packages additional optional packages', async (t) => {
process.chdir('tests/poetry_packages');
const path = npm(['pack', '../..']);
Expand Down

0 comments on commit c1f5ca1

Please sign in to comment.