Skip to content

Commit cc54d84

Browse files
committed
Enhance poetry related logging and add new flag
* Distinct logging whether the requirements.txt file is generated from poetry.lock vs pyproject.toml. * New boolean flag: requirePoetryLockFile - When set to true, fail the build when poetry.lock is missing. This helps with creating reproducible builds where you want to have a fixed poetry.lock file instead of one generated on the fly.
1 parent 891a538 commit cc54d84

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ custom:
114114
usePoetry: false
115115
```
116116

117+
Be aware that if no `poetry.lock` file is present, a new one will be generated on the fly. To help having predictable builds,
118+
you can set the `requirePoetryLockFile` flag to true to throw an error when `poetry.lock` is missing.
119+
120+
```yaml
121+
custom:
122+
pythonRequirements:
123+
requirePoetryLockFile: false
124+
```
125+
117126
### Poetry with git dependencies
118127

119128
Poetry by default generates the exported requirements.txt file with `-e` and that breaks pip with `-t` parameter

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class ServerlessPythonRequirements {
5757
staticCacheMaxVersions: 0,
5858
pipCmdExtraArgs: [],
5959
noDeploy: [],
60-
vendor: ''
60+
vendor: '',
61+
requirePoetryLockFile: false
6162
},
6263
(this.serverless.service.custom &&
6364
this.serverless.service.custom.pythonRequirements) ||

lib/poetry.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ function pyprojectTomlToRequirements() {
1212
return;
1313
}
1414

15-
this.serverless.cli.log('Generating requirements.txt from pyproject.toml...');
15+
const lockFileRes = spawnSync("test", ["-f", "poetry.lock"])
16+
if (lockFileRes.status !== 0) {
17+
this.serverless.cli.log('Generating requirements.txt from poetry.lock...');
18+
} else {
19+
if (this.options.requirePoetryLockFile) {
20+
throw new Error("poetry.lock file not found");
21+
}
22+
this.serverless.cli.log('Generating poetry.lock and requirements.txt from pyproject.toml...');
23+
}
24+
1625

1726
const res = spawnSync(
1827
'poetry',

0 commit comments

Comments
 (0)