@@ -8,24 +8,25 @@ const tomlParse = require('@iarna/toml/parse-string');
88/**
99 * poetry install
1010 */
11- async function pyprojectTomlToRequirements ( ) {
12- if ( ! this . options . usePoetry || ! isPoetryProject ( this . servicePath ) ) {
11+ async function pyprojectTomlToRequirements ( modulePath , pluginInstance ) {
12+ const { serverless, servicePath, options, log, progress } = pluginInstance ;
13+
14+ const moduleProjectPath = path . join ( servicePath , modulePath ) ;
15+ if ( ! options . usePoetry || ! isPoetryProject ( moduleProjectPath ) ) {
1316 return ;
1417 }
1518
1619 let generateRequirementsProgress ;
17- if ( this . progress && this . log ) {
18- generateRequirementsProgress = this . progress . get (
20+ if ( progress && log ) {
21+ generateRequirementsProgress = progress . get (
1922 'python-generate-requirements-toml'
2023 ) ;
2124 generateRequirementsProgress . update (
2225 'Generating requirements.txt from "pyproject.toml"'
2326 ) ;
24- this . log . info ( 'Generating requirements.txt from "pyproject.toml"' ) ;
27+ log . info ( 'Generating requirements.txt from "pyproject.toml"' ) ;
2528 } else {
26- this . serverless . cli . log (
27- 'Generating requirements.txt from pyproject.toml...'
28- ) ;
29+ serverless . cli . log ( 'Generating requirements.txt from pyproject.toml...' ) ;
2930 }
3031
3132 try {
@@ -42,15 +43,15 @@ async function pyprojectTomlToRequirements() {
4243 '--with-credentials' ,
4344 ] ,
4445 {
45- cwd : this . servicePath ,
46+ cwd : moduleProjectPath ,
4647 }
4748 ) ;
4849 } catch ( e ) {
4950 if (
5051 e . stderrBuffer &&
5152 e . stderrBuffer . toString ( ) . includes ( 'command not found' )
5253 ) {
53- throw new this . serverless . classes . Error (
54+ throw new serverless . classes . Error (
5455 `poetry not found! Install it according to the poetry docs.` ,
5556 'PYTHON_REQUIREMENTS_POETRY_NOT_FOUND'
5657 ) ;
@@ -59,16 +60,16 @@ async function pyprojectTomlToRequirements() {
5960 }
6061
6162 const editableFlag = new RegExp ( / ^ - e / gm) ;
62- const sourceRequirements = path . join ( this . servicePath , 'requirements.txt' ) ;
63+ const sourceRequirements = path . join ( moduleProjectPath , 'requirements.txt' ) ;
6364 const requirementsContents = fse . readFileSync ( sourceRequirements , {
6465 encoding : 'utf-8' ,
6566 } ) ;
6667
6768 if ( requirementsContents . match ( editableFlag ) ) {
68- if ( this . log ) {
69- this . log . info ( 'The generated file contains -e flags, removing them' ) ;
69+ if ( log ) {
70+ log . info ( 'The generated file contains -e flags, removing them' ) ;
7071 } else {
71- this . serverless . cli . log (
72+ serverless . cli . log (
7273 'The generated file contains -e flags, removing them...'
7374 ) ;
7475 }
@@ -78,10 +79,10 @@ async function pyprojectTomlToRequirements() {
7879 ) ;
7980 }
8081
81- fse . ensureDirSync ( path . join ( this . servicePath , '.serverless' ) ) ;
82+ fse . ensureDirSync ( path . join ( servicePath , '.serverless' ) ) ;
8283 fse . moveSync (
8384 sourceRequirements ,
84- path . join ( this . servicePath , '.serverless' , 'requirements.txt' ) ,
85+ path . join ( servicePath , '.serverless' , modulePath , 'requirements.txt' ) ,
8586 { overwrite : true }
8687 ) ;
8788 } finally {
0 commit comments