diff --git a/README.md b/README.md index 0b3bad55..b48f2d6f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 09289193..0bd405b5 100644 --- a/index.js +++ b/index.js @@ -57,7 +57,8 @@ class ServerlessPythonRequirements { staticCacheMaxVersions: 0, pipCmdExtraArgs: [], noDeploy: [], - vendor: '' + vendor: '', + requirePoetryLockFile: false }, (this.serverless.service.custom && this.serverless.service.custom.pythonRequirements) || diff --git a/lib/poetry.js b/lib/poetry.js index 553a1392..12a59248 100644 --- a/lib/poetry.js +++ b/lib/poetry.js @@ -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',