@@ -24,7 +24,7 @@ class ServerlessPythonRequirements {
24
24
return BbPromise . resolve ( ) ;
25
25
}
26
26
27
- this . serverless . cli . log ( 'Packaging required Python packages...' ) ;
27
+ this . serverless . cli . log ( 'Installing required Python packages...' ) ;
28
28
29
29
return new BbPromise ( ( resolve , reject ) => {
30
30
let cmd = 'pip' ;
@@ -56,6 +56,7 @@ class ServerlessPythonRequirements {
56
56
return this . installRequirements ( ) . then ( ( ) => {
57
57
return new BbPromise ( ( resolve , reject ) => {
58
58
if ( this . custom . zipImport ) {
59
+ this . serverless . cli . log ( 'Zipping required Python packages...' ) ;
59
60
const zip = new Zip ( ) ;
60
61
zip . addLocalFolder ( '.requirements' , '' ) ;
61
62
zip . writeZip ( '.requirements.zip' ) ;
@@ -65,6 +66,21 @@ class ServerlessPythonRequirements {
65
66
} ) ;
66
67
}
67
68
69
+ linkRequirements ( ) {
70
+ if ( ! this . custom . zipImport && this . custom . link ) {
71
+ this . serverless . cli . log ( 'Linking required Python packages...' ) ;
72
+ fse . readdirSync ( '.requirements' ) . map ( file =>
73
+ fse . symlinkSync ( `.requirements/${ file } ` , `./${ file } ` ) ) ;
74
+ }
75
+ }
76
+
77
+ unlinkRequirements ( ) {
78
+ if ( ! this . custom . zipImport && this . custom . link ) {
79
+ this . serverless . cli . log ( 'Unlinking required Python packages...' ) ;
80
+ fse . readdirSync ( '.requirements' ) . map ( file => fse . unlinkSync ( file ) ) ;
81
+ }
82
+ }
83
+
68
84
cleanup ( ) {
69
85
const artifacts = [ 'requirements.py' ] ;
70
86
if ( this . custom . zipImport )
@@ -79,7 +95,11 @@ class ServerlessPythonRequirements {
79
95
constructor ( serverless , options ) {
80
96
this . serverless = serverless ;
81
97
this . options = options ;
82
- this . custom = this . serverless . service . custom && this . serverless . service . custom . pythonRequirements || { } ;
98
+ this . custom = Object . assign ( {
99
+ zipImport : false ,
100
+ link : true ,
101
+ } , this . serverless . service . custom &&
102
+ this . serverless . service . custom . pythonRequirements || { } ) ;
83
103
84
104
this . commands = {
85
105
'requirements' : {
@@ -103,14 +123,19 @@ class ServerlessPythonRequirements {
103
123
this . hooks = {
104
124
'before:deploy:createDeploymentArtifacts' : ( ) => BbPromise . bind ( this )
105
125
. then ( this . packVendorHelper )
106
- . then ( this . packRequirements ) ,
126
+ . then ( this . packRequirements )
127
+ . then ( this . linkRequirements ) ,
128
+
129
+ 'after:deploy:createDeploymentArtifacts' : ( ) => BbPromise . bind ( this )
130
+ . then ( this . unlinkRequirements ) ,
107
131
108
132
'requirements:install:install' : ( ) => BbPromise . bind ( this )
109
133
. then ( this . packVendorHelper )
110
134
. then ( this . packRequirements ) ,
111
135
112
136
'requirements:clean:clean' : ( ) => BbPromise . bind ( this )
113
137
. then ( this . cleanup )
138
+ . then ( this . unlinkRequirements ) ,
114
139
} ;
115
140
}
116
141
}
0 commit comments