@@ -41,41 +41,13 @@ class ServerlessPythonRequirements {
41
41
}
42
42
} ;
43
43
44
- /**
45
- * parse requirements.txt into .requirements.txt, leaving out #no-deploy lines
46
- * @return {true }
47
- */
48
- parseRequirements ( ) {
49
- if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath ,
50
- 'requirements.txt' ) ) ) {
51
- return true ;
52
- }
53
-
54
- this . serverless . cli . log (
55
- `Parsing Python requirements.txt` ) ;
56
-
57
- const reqs = fse . readFileSync ( 'requirements.txt' ) . toString ( ) . split ( '\n' ) ;
58
-
59
- let newReqs = '' ;
60
- for ( const req of reqs ) {
61
- if ( req . indexOf ( '#no-deploy' ) === - 1 ) {
62
- newReqs += `${ req } \n` ;
63
- }
64
- }
65
- if ( ! fse . existsSync ( '.serverless' ) )
66
- fse . mkdirSync ( '.serverless' ) ;
67
- fse . writeFileSync ( '.serverless/requirements.txt' , newReqs , 'utf8' ) ;
68
-
69
- return true ;
70
- } ;
71
-
72
44
/**
73
45
* pip install the requirements to the .requirements directory
74
46
* @return {Promise }
75
47
*/
76
48
installRequirements ( ) {
77
49
if ( ! fse . existsSync ( path . join ( this . serverless . config . servicePath ,
78
- '.serverless/ requirements.txt' ) ) ) {
50
+ 'requirements.txt' ) ) ) {
79
51
return BbPromise . resolve ( ) ;
80
52
}
81
53
@@ -88,7 +60,7 @@ class ServerlessPythonRequirements {
88
60
let options ;
89
61
const pipCmd = [
90
62
runtime , '-m' , 'pip' , '--isolated' , 'install' ,
91
- '-t' , '.requirements' , '-r' , '.serverless/ requirements.txt' ,
63
+ '-t' , '.requirements' , '-r' , 'requirements.txt' ,
92
64
] ;
93
65
if ( this . custom ( ) . pipCmdExtraArgs ) {
94
66
pipCmd . push ( ...this . custom ( ) . pipCmdExtraArgs ) ;
@@ -148,9 +120,12 @@ class ServerlessPythonRequirements {
148
120
linkRequirements ( ) {
149
121
if ( ! this . custom ( ) . zip ) {
150
122
this . serverless . cli . log ( 'Linking required Python packages...' ) ;
123
+ const noDeploy = new Set ( this . custom ( ) . noDeploy || [ ] ) ;
151
124
fse . readdirSync ( '.requirements' ) . map ( ( file ) => {
152
- this . serverless . service . package . include . push ( file ) ;
153
- this . serverless . service . package . include . push ( `${ file } /**` ) ;
125
+ if ( noDeploy . has ( file ) )
126
+ return ;
127
+ this . serverless . service . package . include . push ( file ) ;
128
+ this . serverless . service . package . include . push ( `${ file } /**` ) ;
154
129
try {
155
130
fse . symlinkSync ( `.requirements/${ file } ` , `./${ file } ` ) ;
156
131
} catch ( exception ) {
@@ -159,11 +134,10 @@ class ServerlessPythonRequirements {
159
134
linkDest = fse . readlinkSync ( `./${ file } ` ) ;
160
135
} catch ( e ) { }
161
136
if ( linkDest !== `.requirements/${ file } ` )
162
- throw new Error ( `Unable to link dependency '${ file } ' because a file
163
- by the same name exists in this service` ) ;
137
+ throw new Error ( `Unable to link dependency '${ file } ' because a file
138
+ by the same name exists in this service` ) ;
164
139
}
165
- }
166
- ) ;
140
+ } ) ;
167
141
}
168
142
}
169
143
@@ -244,7 +218,6 @@ class ServerlessPythonRequirements {
244
218
245
219
let before = ( ) => BbPromise . bind ( this )
246
220
. then ( this . addVendorHelper )
247
- . then ( this . parseRequirements )
248
221
. then ( this . packRequirements )
249
222
. then ( this . linkRequirements ) ;
250
223
@@ -270,7 +243,6 @@ class ServerlessPythonRequirements {
270
243
'after:deploy:function:packageFunction' : after ,
271
244
'requirements:install:install' : ( ) => BbPromise . bind ( this )
272
245
. then ( this . addVendorHelper )
273
- . then ( this . parseRequirements )
274
246
. then ( this . packRequirements ) ,
275
247
'requirements:clean:clean' : ( ) => BbPromise . bind ( this )
276
248
. then ( this . cleanup )
0 commit comments