From 495376ccd43af4e72cdeb9ef5ac9e7fbed705875 Mon Sep 17 00:00:00 2001 From: "Ryan S. Brown" Date: Sat, 23 Jan 2016 10:24:29 -0500 Subject: [PATCH] Add utility for pip installation using `-t` --- lib/actions/ComponentCreate.js | 2 +- lib/utils/index.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/actions/ComponentCreate.js b/lib/actions/ComponentCreate.js index 1c08d790b..a7af4851e 100644 --- a/lib/actions/ComponentCreate.js +++ b/lib/actions/ComponentCreate.js @@ -232,7 +232,7 @@ usage: serverless component create`, _installComponentDependencies() { let _this = this; - if (_this.runtime === 'nodejs') { + if (_this.evt.options.runtime === 'nodejs') { SCli.log('Installing "serverless-helpers" for this component via NPM...'); SUtils.npmInstall(path.join(this.S.config.projectPath, this.evt.options.component)); } else if (_this.runtime === 'python2.7') { diff --git a/lib/utils/index.js b/lib/utils/index.js index c7cf3bed6..5f0f66fdc 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -539,6 +539,17 @@ exports.npmInstall = function(dir) { process.chdir(process.cwd()); }; +/** + * Pip install using prefix strategy (not virtualenv), requires a modern `pip` version + */ +exports.pipPrefixInstall = function(requirements, dir) { + if (exec(`pip install -t "${dir}" -r "${requirements}"`, { silent: false }).code !== 0) { + throw new SError(`Error executing pip install on ${dir}`, SError.errorCodes.UNKNOWN); + } + + process.chdir(process.cwd()); +}; + /** * Write to console.log if process.env.DEBUG is true * - If we ever want to get more complicated with log levels we should use winston