@@ -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' ] ) ;
@@ -208,6 +235,7 @@ class ServerlessPythonRequirements {
208
235
209
236
let before = ( ) => BbPromise . bind ( this )
210
237
. then ( this . addVendorHelper )
238
+ . then ( this . parseRequirements )
211
239
. then ( this . packRequirements )
212
240
. then ( this . linkRequirements ) ;
213
241
@@ -222,6 +250,7 @@ class ServerlessPythonRequirements {
222
250
'after:deploy:function:packageFunction' : after ,
223
251
'requirements:install:install' : ( ) => BbPromise . bind ( this )
224
252
. then ( this . addVendorHelper )
253
+ . then ( this . parseRequirements )
225
254
. then ( this . packRequirements ) ,
226
255
'requirements:clean:clean' : ( ) => BbPromise . bind ( this )
227
256
. then ( this . cleanup )
0 commit comments