Skip to content
Closed
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: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ custom:
usePoetry: false
```

Be aware that if no `poetry.lock` file is present, a new one will be generated on the fly. To help having predictable builds,
you can set the `requirePoetryLockFile` flag to true to throw an error when `poetry.lock` is missing.

```yaml
custom:
pythonRequirements:
requirePoetryLockFile: false
```

### Poetry with git dependencies

Poetry by default generates the exported requirements.txt file with `-e` and that breaks pip with `-t` parameter
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class ServerlessPythonRequirements {
staticCacheMaxVersions: 0,
pipCmdExtraArgs: [],
noDeploy: [],
vendor: ''
vendor: '',
requirePoetryLockFile: false
},
(this.serverless.service.custom &&
this.serverless.service.custom.pythonRequirements) ||
Expand Down
16 changes: 15 additions & 1 deletion lib/poetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@ function pyprojectTomlToRequirements() {
return;
}

this.serverless.cli.log('Generating requirements.txt from pyproject.toml...');
const lockFileRes = spawnSync("test", ["-f", "poetry.lock"])
if (lockFileRes.status !== 0) {
this.serverless.cli.log('Generating requirements.txt from poetry.lock...');
} else {
if (this.options.requirePoetryLockFile) {
throw new Error(
"poetry.lock file not found - set requirePoetryLockFile to false to "
+ "disable this error"
);
}
this.serverless.cli.log(
'Generating poetry.lock and requirements.txt from pyproject.toml...'
);
}


const res = spawnSync(
'poetry',
Expand Down