Skip to content

Commit 5177cdd

Browse files
authored
Merge pull request serverless#477 from miketheman/miketheman/fix-400
fix: check if pyproject has poetry earlier
2 parents 6ecc5ad + 1bc999d commit 5177cdd

File tree

8 files changed

+87
-3
lines changed

8 files changed

+87
-3
lines changed

lib/pip.js

+7-2
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,9 @@ function generateRequirementsFile(
6263
) {
6364
if (
6465
options.usePoetry &&
65-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
66+
fse.existsSync(
67+
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
68+
)
6669
) {
6770
filterRequirementsFile(
6871
path.join(servicePath, '.serverless/requirements.txt'),
@@ -442,7 +445,9 @@ function copyVendors(vendorFolder, targetFolder, serverless) {
442445
function requirementsFileExists(servicePath, options, fileName) {
443446
if (
444447
options.usePoetry &&
445-
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
448+
fse.existsSync(
449+
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
450+
)
446451
) {
447452
return true;
448453
}

lib/poetry.js

+1-1
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 };

test.js

+10
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,16 @@ test('non build pyproject.toml uses requirements.txt', t => {
748748
t.end();
749749
});
750750

751+
test('non poetry pyproject.toml without requirements.txt packages handler only', t => {
752+
process.chdir('tests/non_poetry_pyproject');
753+
const path = npm(['pack', '../..']);
754+
npm(['i', path]);
755+
sls(['package']);
756+
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
757+
t.true(zipfiles.includes(`handler.py`), 'handler is packaged');
758+
t.end();
759+
});
760+
751761
test('poetry py3.6 can package flask with default options', t => {
752762
process.chdir('tests/poetry');
753763
const path = npm(['pack', '../..']);

tests/non_poetry_pyproject/.gitignore

+22
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

+5
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()
+14
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+
}
+10
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+
'''
+18
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)