Skip to content

Commit f4390b2

Browse files
committed
Better mixed runtime & function deploy handling
fixes #161 and fixes #179
1 parent 94e9894 commit f4390b2

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

index.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,28 @@ class ServerlessPythonRequirements {
108108
}
109109
};
110110

111-
const before = () =>
112-
BbPromise.bind(this)
111+
const before = () => {
112+
if (arguments[1].functionObj && arguments[1].functionObj.runtime && !arguments[1].functionObj.runtime.startsWith('python'))
113+
return;
114+
return BbPromise.bind(this)
113115
.then(pipfileToRequirements)
114116
.then(addVendorHelper)
115117
.then(installAllRequirements)
116118
.then(packRequirements);
119+
}
117120

118-
const after = () =>
119-
BbPromise.bind(this)
121+
const after = wat => {
122+
if (arguments[1].functionObj && arguments[1].functionObj.runtime && !arguments[1].functionObj.runtime.startsWith('python'))
123+
return;
124+
return BbPromise.bind(this)
120125
.then(removeVendorHelper)
121-
.then(injectAllRequirements);
126+
.then(() =>
127+
injectAllRequirements.bind(this)(
128+
arguments[1].functionObj &&
129+
arguments[1].functionObj.package.artifact
130+
)
131+
);
132+
};
122133

123134
const invalidateCaches = () => {
124135
if (this.options.invalidateCaches) {

lib/inject.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function moveModuleUp(source, target, module) {
7272
* Inject requirements into packaged application.
7373
* @return {Promise} the combined promise for requirements injection.
7474
*/
75-
function injectAllRequirements() {
75+
function injectAllRequirements(artifact) {
7676
this.serverless.cli.log('Injecting required Python packages to package...');
7777

7878
if (this.options.zip) {
@@ -107,14 +107,14 @@ function injectAllRequirements() {
107107
.map(func =>
108108
injectRequirements(
109109
path.join('.serverless', func.module, 'requirements'),
110-
func.package.artifact,
110+
func.package ? func.package.artifact : artifact,
111111
this.options
112112
)
113113
);
114114
} else {
115115
return injectRequirements(
116116
path.join('.serverless', 'requirements'),
117-
this.serverless.service.package.artifact,
117+
artifact || this.serverless.service.package.artifact,
118118
this.options
119119
);
120120
}

tests/base/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"author": "",
1010
"license": "ISC",
1111
"dependencies": {
12-
"serverless-python-requirements": "file:serverless-python-requirements-4.0.0.tgz"
12+
"serverless-python-requirements": "file:serverless-python-requirements-4.0.2.tgz"
1313
}
1414
}

0 commit comments

Comments
 (0)