Skip to content

Commit 166ae65

Browse files
committedOct 1, 2022
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 a4cd36b commit 166ae65

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed
 

‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ custom:
131131
usePoetry: false
132132
```
133133

134+
Be aware that if no `poetry.lock` file is present, a new one will be generated on the fly. To help having predictable builds,
135+
you can set the `requirePoetryLockFile` flag to true to throw an error when `poetry.lock` is missing.
136+
137+
```yaml
138+
custom:
139+
pythonRequirements:
140+
requirePoetryLockFile: false
141+
```
142+
134143
### Poetry with git dependencies
135144

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

‎index.js

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

‎lib/poetry.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,27 @@ async function pyprojectTomlToRequirements(modulePath, pluginInstance) {
2121
generateRequirementsProgress = progress.get(
2222
'python-generate-requirements-toml'
2323
);
24-
generateRequirementsProgress.update(
25-
'Generating requirements.txt from "pyproject.toml"'
26-
);
27-
log.info('Generating requirements.txt from "pyproject.toml"');
24+
}
25+
26+
const emitMsg = (msg) => {
27+
if (generateRequirementsProgress) {
28+
generateRequirementsProgress.update(msg);
29+
log.info(msg);
30+
} else {
31+
serverless.cli.log(msg);
32+
}
33+
};
34+
35+
if (fs.existsSync('poetry.lock')) {
36+
emitMsg('Generating requirements.txt from poetry.lock');
2837
} else {
29-
serverless.cli.log('Generating requirements.txt from pyproject.toml...');
38+
if (options.requirePoetryLockFile) {
39+
throw new serverless.classes.Error(
40+
'poetry.lock file not found - set requirePoetryLockFile to false to ' +
41+
'disable this error'
42+
);
43+
}
44+
emitMsg('Generating poetry.lock and requirements.txt from pyproject.toml');
3045
}
3146

3247
try {

0 commit comments

Comments
 (0)
Failed to load comments.