Skip to content

Commit 5048c6d

Browse files
mikethemanbsamuel-ui
authored andcommitted
fix: check if pyproject has poetry earlier
During the evaluation in the package phase, we determine whether a `requirements.txt` file exists, or whether we need to generate one. Since the `pyproject.toml` file is used by poetry, but only if a stanza is contained inside the file, use the function `isPoetryProject()` along with the configuration value, thereby reducing the need for a project to have to declare a configuration override. Refs #324 Refs #344 Fixes #400 Signed-off-by: Mike Fiedler <[email protected]>
1 parent 5d956e9 commit 5048c6d

File tree

7 files changed

+77
-3
lines changed

7 files changed

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

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)