@@ -39,13 +39,40 @@ class ServerlessPythonRequirements {
39
39
}
40
40
} ;
41
41
42
+ /**
43
+ * parse requirements.txt into .requirements.txt, leaving out #no-deploy lines
44
+ * @return true
45
+ */
46
+ parseRequirements ( ) {
47
+ if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath ,
48
+ 'requirements.txt' ) ) ) {
49
+ return BbPromise . resolve ( ) ;
50
+ }
51
+
52
+ this . serverless . cli . log (
53
+ `Parsing Python requirements.txt` ) ;
54
+
55
+ var fs = require ( 'fs' ) ;
56
+ var reqs = fs . readFileSync ( "requirements.txt" ) . toString ( ) . split ( '\n' ) ;
57
+
58
+ var newReqs = ''
59
+ for ( var i in reqs ) {
60
+ if ( reqs [ i ] . indexOf ( '#no-deploy' ) == - 1 ) {
61
+ newReqs += reqs [ i ] + '\n'
62
+ }
63
+ }
64
+ fs . writeFileSync ( ".requirements.txt" , newReqs , 'utf8' ) ;
65
+
66
+ return true
67
+ } ;
68
+
42
69
/**
43
70
* pip install the requirements to the .requirements directory
44
71
* @return {Promise }
45
72
*/
46
73
installRequirements ( ) {
47
74
if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath ,
48
- 'requirements.txt' ) ) ) {
75
+ '. requirements.txt' ) ) ) {
49
76
return BbPromise . resolve ( ) ;
50
77
}
51
78
@@ -58,7 +85,7 @@ class ServerlessPythonRequirements {
58
85
let options ;
59
86
const pipCmd = [
60
87
runtime , '-m' , 'pip' , '--isolated' , 'install' ,
61
- '-t' , '.requirements' , '-r' , 'requirements.txt' ,
88
+ '-t' , '.requirements' , '-r' , '. requirements.txt' ,
62
89
] ;
63
90
if ( ! this . custom ( ) . dockerizePip ) {
64
91
const pipTestRes = spawnSync ( runtime , [ '-m' , 'pip' , 'help' , 'install' ] ) ;
@@ -204,6 +231,7 @@ class ServerlessPythonRequirements {
204
231
205
232
let before = ( ) => BbPromise . bind ( this )
206
233
. then ( this . addVendorHelper )
234
+ . then ( this . parseRequirements )
207
235
. then ( this . packRequirements )
208
236
. then ( this . linkRequirements ) ;
209
237
@@ -218,6 +246,7 @@ class ServerlessPythonRequirements {
218
246
'after:deploy:function:packageFunction' : after ,
219
247
'requirements:install:install' : ( ) => BbPromise . bind ( this )
220
248
. then ( this . addVendorHelper )
249
+ . then ( this . parseRequirements )
221
250
. then ( this . packRequirements ) ,
222
251
'requirements:clean:clean' : ( ) => BbPromise . bind ( this )
223
252
. then ( this . cleanup )
0 commit comments