Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 298faea

Browse files
committed
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 serverless#324 Refs serverless#344 Fixes serverless#400 Signed-off-by: Mike Fiedler <[email protected]>
1 parent 724955e commit 298faea

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/pip.js

Lines changed: 5 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,8 @@ 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(path.join(servicePath, 'pyproject.toml') &&
448+
isPoetryProject(servicePath))
446449
) {
447450
return true;
448451
}

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

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,16 @@ test('non build pyproject.toml uses requirements.txt', t => {
744744
t.end();
745745
});
746746

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

0 commit comments

Comments
 (0)