Skip to content

Commit f96e42e

Browse files
committed
Merge branch 'master' into feature/github-actions
# Conflicts: # package.json # test.js
2 parents 89c74d8 + b652947 commit f96e42e

File tree

9 files changed

+91
-4
lines changed

9 files changed

+91
-4
lines changed

lib/pip.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { spawnSync } = require('child_process');
77
const { quote } = require('shell-quote');
88
const { buildImage, getBindPath, getDockerUid } = require('./docker');
99
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
10+
const { isPoetryProject } = require('./poetry');
1011
const {
1112
checkForAndDeleteMaxCacheVersions,
1213
sha256Path,
@@ -62,7 +63,8 @@ function generateRequirementsFile(
6263
) {
6364
if (
6465
options.usePoetry &&
65-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
66+
fse.existsSync(path.join(servicePath, 'pyproject.toml')) &&
67+
isPoetryProject(servicePath)
6668
) {
6769
filterRequirementsFile(
6870
path.join(servicePath, '.serverless/requirements.txt'),
@@ -442,7 +444,9 @@ function copyVendors(vendorFolder, targetFolder, serverless) {
442444
function requirementsFileExists(servicePath, options, fileName) {
443445
if (
444446
options.usePoetry &&
445-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
447+
fse.existsSync(
448+
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
449+
)
446450
) {
447451
return true;
448452
}

lib/poetry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ function isPoetryProject(servicePath) {
9090
return false;
9191
}
9292

93-
module.exports = { pyprojectTomlToRequirements };
93+
module.exports = { pyprojectTomlToRequirements, isPoetryProject };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"format": "prettier --write '{.,lib}/*.{js,md}'"
4545
},
4646
"devDependencies": {
47-
"eslint": "^5.16.0",
47+
"eslint": "^6.8.0",
4848
"prettier": "^1",
4949
"cross-spawn": "*",
5050
"tape": "*",

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,20 @@ test(
927927
{ skip: !hasPython(3.6) }
928928
);
929929

930+
test(
931+
'non poetry pyproject.toml without requirements.txt packages handler only',
932+
async t => {
933+
process.chdir('tests/non_poetry_pyproject');
934+
const path = npm(['pack', '../..']);
935+
npm(['i', path]);
936+
sls(['package']);
937+
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
938+
t.true(zipfiles.includes(`handler.py`), 'handler is packaged');
939+
t.end();
940+
},
941+
{ skip: !hasPython(3.6) }
942+
);
943+
930944
test(
931945
'poetry py3.6 can package flask with default options',
932946
async t => {

tests/non_poetry_pyproject/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Distribution / packaging
2+
.Python
3+
env/
4+
build/
5+
develop-eggs/
6+
dist/
7+
downloads/
8+
eggs/
9+
.eggs/
10+
lib/
11+
lib64/
12+
parts/
13+
sdist/
14+
var/
15+
*.egg-info/
16+
.installed.cfg
17+
*.egg
18+
19+
# Serverless
20+
.serverless
21+
.requirements
22+
unzip_requirements.py

tests/non_poetry_pyproject/handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import requests
2+
3+
4+
def hello(event, context):
5+
return requests.get('https://httpbin.org/get').json()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "example",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"serverless-python-requirements": "file:serverless-python-requirements-5.1.0.tgz"
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.black]
2+
line-length = 79
3+
py36 = true
4+
skip-string-normalization = true
5+
exclude = '''
6+
/(
7+
\.serverless
8+
| node_modules
9+
)/
10+
'''
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
service: sls-py-req-test
2+
3+
provider:
4+
name: aws
5+
runtime: python3.6
6+
7+
plugins:
8+
- serverless-python-requirements
9+
10+
package:
11+
exclude:
12+
- '**/*'
13+
include:
14+
- handler.py
15+
16+
functions:
17+
hello:
18+
handler: handler.hello

0 commit comments

Comments
 (0)