Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { spawnSync } = require('child_process');
const { quote } = require('shell-quote');
const { buildImage, getBindPath, getDockerUid } = require('./docker');
const { getStripCommand, getStripMode, deleteFiles } = require('./slim');
const { isPoetryProject } = require('./poetry');
const {
checkForAndDeleteMaxCacheVersions,
sha256Path,
Expand Down Expand Up @@ -62,7 +63,9 @@ function generateRequirementsFile(
) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
fse.existsSync(
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
)
) {
filterRequirementsFile(
path.join(servicePath, '.serverless/requirements.txt'),
Expand Down Expand Up @@ -442,7 +445,9 @@ function copyVendors(vendorFolder, targetFolder, serverless) {
function requirementsFileExists(servicePath, options, fileName) {
if (
options.usePoetry &&
fse.existsSync(path.join(servicePath, 'pyproject.toml'))
fse.existsSync(
path.join(servicePath, 'pyproject.toml') && isPoetryProject(servicePath)
)
) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/poetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ function isPoetryProject(servicePath) {
return false;
}

module.exports = { pyprojectTomlToRequirements };
module.exports = { pyprojectTomlToRequirements, isPoetryProject };
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,16 @@ test('non build pyproject.toml uses requirements.txt', t => {
t.end();
});

test('non poetry pyproject.toml without requirements.txt packages handler only', t => {
process.chdir('tests/non_poetry_pyproject');
const path = npm(['pack', '../..']);
npm(['i', path]);
sls(['package']);
const zipfiles = listZipFiles('.serverless/sls-py-req-test.zip');
t.true(zipfiles.includes(`handler.py`), 'handler is packaged');
t.end();
});

test('poetry py3.6 can package flask with default options', t => {
process.chdir('tests/poetry');
const path = npm(['pack', '../..']);
Expand Down
22 changes: 22 additions & 0 deletions tests/non_poetry_pyproject/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Serverless
.serverless
.requirements
unzip_requirements.py
5 changes: 5 additions & 0 deletions tests/non_poetry_pyproject/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import requests


def hello(event, context):
return requests.get('https://httpbin.org/get').json()
14 changes: 14 additions & 0 deletions tests/non_poetry_pyproject/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"serverless-python-requirements": "file:serverless-python-requirements-5.1.0.tgz"
}
}
10 changes: 10 additions & 0 deletions tests/non_poetry_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.black]
line-length = 79
py36 = true
skip-string-normalization = true
exclude = '''
/(
\.serverless
| node_modules
)/
'''
18 changes: 18 additions & 0 deletions tests/non_poetry_pyproject/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
service: sls-py-req-test

provider:
name: aws
runtime: python3.6

plugins:
- serverless-python-requirements

package:
exclude:
- '**/*'
include:
- handler.py

functions:
hello:
handler: handler.hello