Skip to content

Commit c1f5ca1

Browse files
jameskbridemklenbw
andauthored
fix: Not crash when runtime is not python (#773)
Co-authored-by: Marco Kleinlein <[email protected]>
1 parent ad40278 commit c1f5ca1

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ unzip_requirements.py
7676
# Project ignores
7777
puck/
7878
serverless.yml.bak
79+
80+
# Generated packaging
81+
*.tgz

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.7

CONTRIBUTING.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ Welcome, and thanks in advance for your help!
1212

1313
## Setup
1414

15-
It is recommended to use Node v14 or v16 for development.
16-
17-
Then, to begin development fork repository and run `npm install` in its root folder.
15+
Pre-Reqs:
16+
* Python 3.7
17+
* [poetry](https://python-poetry.org/docs/) (if you use multiple versions of Python be sure to install it with python 3.7)
18+
* Perl (used in the tests)
19+
* Node v14 or v16
20+
21+
Then, to begin development:
22+
1. fork the repository
23+
2. `npm install -g serverless@<VERSION>` (check the peer dependencies in the root `package.json` file for the version)
24+
3. run `npm install` in its root folder
25+
4. run the tests via `npm run test`
1826

1927
## Getting started
2028

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class ServerlessPythonRequirements {
6666
this.serverless.service.custom.pythonRequirements) ||
6767
{}
6868
);
69+
if (
70+
options.pythonBin === this.serverless.service.provider.runtime &&
71+
!options.pythonBin.startsWith('python')
72+
) {
73+
options.pythonBin = 'python';
74+
}
75+
6976
if (options.dockerizePip === 'non-linux') {
7077
options.dockerizePip = process.platform !== 'linux';
7178
}

test.js

+12
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,18 @@ test('poetry py3.7 fails packaging if poetry.lock is missing and flag requirePoe
16551655
t.end();
16561656
});
16571657

1658+
test('works with provider.runtime not being python', async (t) => {
1659+
process.chdir('tests/base');
1660+
const path = npm(['pack', '../..']);
1661+
npm(['i', path]);
1662+
sls(['package'], { env: { runtime: 'nodejs12.x' } });
1663+
t.true(
1664+
pathExistsSync('.serverless/sls-py-req-test.zip'),
1665+
'sls-py-req-test is packaged'
1666+
);
1667+
t.end();
1668+
});
1669+
16581670
test('poetry py3.7 packages additional optional packages', async (t) => {
16591671
process.chdir('tests/poetry_packages');
16601672
const path = npm(['pack', '../..']);

0 commit comments

Comments
 (0)