Skip to content

Fix runtime not being python (cont.) #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 17, 2023
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