@@ -8,24 +8,25 @@ const tomlParse = require('@iarna/toml/parse-string');
8
8
/**
9
9
* poetry install
10
10
*/
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 ) ) {
13
16
return ;
14
17
}
15
18
16
19
let generateRequirementsProgress ;
17
- if ( this . progress && this . log ) {
18
- generateRequirementsProgress = this . progress . get (
20
+ if ( progress && log ) {
21
+ generateRequirementsProgress = progress . get (
19
22
'python-generate-requirements-toml'
20
23
) ;
21
24
generateRequirementsProgress . update (
22
25
'Generating requirements.txt from "pyproject.toml"'
23
26
) ;
24
- this . log . info ( 'Generating requirements.txt from "pyproject.toml"' ) ;
27
+ log . info ( 'Generating requirements.txt from "pyproject.toml"' ) ;
25
28
} else {
26
- this . serverless . cli . log (
27
- 'Generating requirements.txt from pyproject.toml...'
28
- ) ;
29
+ serverless . cli . log ( 'Generating requirements.txt from pyproject.toml...' ) ;
29
30
}
30
31
31
32
try {
@@ -42,15 +43,15 @@ async function pyprojectTomlToRequirements() {
42
43
'--with-credentials' ,
43
44
] ,
44
45
{
45
- cwd : this . servicePath ,
46
+ cwd : moduleProjectPath ,
46
47
}
47
48
) ;
48
49
} catch ( e ) {
49
50
if (
50
51
e . stderrBuffer &&
51
52
e . stderrBuffer . toString ( ) . includes ( 'command not found' )
52
53
) {
53
- throw new this . serverless . classes . Error (
54
+ throw new serverless . classes . Error (
54
55
`poetry not found! Install it according to the poetry docs.` ,
55
56
'PYTHON_REQUIREMENTS_POETRY_NOT_FOUND'
56
57
) ;
@@ -59,16 +60,16 @@ async function pyprojectTomlToRequirements() {
59
60
}
60
61
61
62
const editableFlag = new RegExp ( / ^ - e / gm) ;
62
- const sourceRequirements = path . join ( this . servicePath , 'requirements.txt' ) ;
63
+ const sourceRequirements = path . join ( moduleProjectPath , 'requirements.txt' ) ;
63
64
const requirementsContents = fse . readFileSync ( sourceRequirements , {
64
65
encoding : 'utf-8' ,
65
66
} ) ;
66
67
67
68
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' ) ;
70
71
} else {
71
- this . serverless . cli . log (
72
+ serverless . cli . log (
72
73
'The generated file contains -e flags, removing them...'
73
74
) ;
74
75
}
@@ -78,10 +79,10 @@ async function pyprojectTomlToRequirements() {
78
79
) ;
79
80
}
80
81
81
- fse . ensureDirSync ( path . join ( this . servicePath , '.serverless' ) ) ;
82
+ fse . ensureDirSync ( path . join ( servicePath , '.serverless' ) ) ;
82
83
fse . moveSync (
83
84
sourceRequirements ,
84
- path . join ( this . servicePath , '.serverless' , 'requirements.txt' ) ,
85
+ path . join ( servicePath , '.serverless' , modulePath , 'requirements.txt' ) ,
85
86
{ overwrite : true }
86
87
) ;
87
88
} finally {
0 commit comments