@@ -12,57 +12,76 @@ function pyprojectTomlToRequirements() {
12
12
return ;
13
13
}
14
14
15
- this . serverless . cli . log ( 'Generating requirements.txt from pyproject.toml...' ) ;
15
+ let generateRequirementsProgress ;
16
+ if ( this . progress ) {
17
+ generateRequirementsProgress = this . progress . get (
18
+ 'python-generate-requirements-toml'
19
+ ) ;
20
+ } else {
21
+ this . serverless . cli . log (
22
+ 'Generating requirements.txt from pyproject.toml...'
23
+ ) ;
24
+ }
16
25
17
- const res = spawnSync (
18
- 'poetry' ,
19
- [
20
- 'export' ,
21
- '--without-hashes' ,
22
- '-f' ,
23
- 'requirements.txt' ,
24
- '-o' ,
25
- 'requirements.txt' ,
26
- '--with-credentials' ,
27
- ] ,
28
- {
29
- cwd : this . servicePath ,
26
+ try {
27
+ const res = spawnSync (
28
+ 'poetry' ,
29
+ [
30
+ 'export' ,
31
+ '--without-hashes' ,
32
+ '-f' ,
33
+ 'requirements.txt' ,
34
+ '-o' ,
35
+ 'requirements.txt' ,
36
+ '--with-credentials' ,
37
+ ] ,
38
+ {
39
+ cwd : this . servicePath ,
40
+ }
41
+ ) ;
42
+ if ( res . error ) {
43
+ if ( res . error . code === 'ENOENT' ) {
44
+ throw new Error (
45
+ `poetry not found! Install it according to the poetry docs.`
46
+ ) ;
47
+ }
48
+ throw new Error ( res . error ) ;
30
49
}
31
- ) ;
32
- if ( res . error ) {
33
- if ( res . error . code === 'ENOENT' ) {
34
- throw new Error (
35
- `poetry not found! Install it according to the poetry docs.`
36
- ) ;
50
+ if ( res . status !== 0 ) {
51
+ throw new Error ( res . stderr ) ;
37
52
}
38
- throw new Error ( res . error ) ;
39
- }
40
- if ( res . status !== 0 ) {
41
- throw new Error ( res . stderr ) ;
42
- }
43
53
44
- const editableFlag = new RegExp ( / ^ - e / gm) ;
45
- const sourceRequirements = path . join ( this . servicePath , 'requirements.txt' ) ;
46
- const requirementsContents = fse . readFileSync ( sourceRequirements , {
47
- encoding : 'utf-8' ,
48
- } ) ;
54
+ const editableFlag = new RegExp ( / ^ - e / gm) ;
55
+ const sourceRequirements = path . join ( this . servicePath , 'requirements.txt' ) ;
56
+ const requirementsContents = fse . readFileSync ( sourceRequirements , {
57
+ encoding : 'utf-8' ,
58
+ } ) ;
49
59
50
- if ( requirementsContents . match ( editableFlag ) ) {
51
- this . serverless . cli . log (
52
- 'The generated file contains -e flags, removing them...'
53
- ) ;
54
- fse . writeFileSync (
60
+ if ( requirementsContents . match ( editableFlag ) ) {
61
+ if ( this . log ) {
62
+ this . log . info (
63
+ 'The generated file contains -e flags, removing them'
64
+ ) ;
65
+ } else {
66
+ this . serverless . cli . log (
67
+ 'The generated file contains -e flags, removing them...'
68
+ ) ;
69
+ }
70
+ fse . writeFileSync (
71
+ sourceRequirements ,
72
+ requirementsContents . replace ( editableFlag , '' )
73
+ ) ;
74
+ }
75
+
76
+ fse . ensureDirSync ( path . join ( this . servicePath , '.serverless' ) ) ;
77
+ fse . moveSync (
55
78
sourceRequirements ,
56
- requirementsContents . replace ( editableFlag , '' )
79
+ path . join ( this . servicePath , '.serverless' , 'requirements.txt' ) ,
80
+ { overwrite : true }
57
81
) ;
82
+ } finally {
83
+ generateRequirementsProgress && generateRequirementsProgress . remove ( ) ;
58
84
}
59
-
60
- fse . ensureDirSync ( path . join ( this . servicePath , '.serverless' ) ) ;
61
- fse . moveSync (
62
- sourceRequirements ,
63
- path . join ( this . servicePath , '.serverless' , 'requirements.txt' ) ,
64
- { overwrite : true }
65
- ) ;
66
85
}
67
86
68
87
/**
0 commit comments