diff --git a/index.js b/index.js index 55347482..a63b12b8 100644 --- a/index.js +++ b/index.js @@ -39,13 +39,40 @@ class ServerlessPythonRequirements { } }; + /** + * parse requirements.txt into .requirements.txt, leaving out #no-deploy lines + * @return true + */ + parseRequirements() { + if (!fse.existsSync(path.join(this.serverless.config.servicePath, + 'requirements.txt'))) { + return BbPromise.resolve(); + } + + this.serverless.cli.log( + `Parsing Python requirements.txt`); + + var fs = require('fs'); + var reqs = fs.readFileSync("requirements.txt").toString().split('\n'); + + var newReqs = '' + for (var i in reqs) { + if(reqs[i].indexOf('#no-deploy') == -1) { + newReqs += reqs[i] + '\n' + } + } + fs.writeFileSync(".requirements.txt", newReqs, 'utf8'); + + return true + }; + /** * pip install the requirements to the .requirements directory * @return {Promise} */ installRequirements() { if (!fse.existsSync(path.join(this.serverless.config.servicePath, - 'requirements.txt'))) { + '.requirements.txt'))) { return BbPromise.resolve(); } @@ -58,7 +85,7 @@ class ServerlessPythonRequirements { let options; const pipCmd = [ runtime, '-m', 'pip', '--isolated', 'install', - '-t', '.requirements', '-r', 'requirements.txt', + '-t', '.requirements', '-r', '.requirements.txt', ]; if (!this.custom().dockerizePip) { const pipTestRes = spawnSync(runtime, ['-m', 'pip', 'help', 'install']); @@ -204,6 +231,7 @@ class ServerlessPythonRequirements { let before = () => BbPromise.bind(this) .then(this.addVendorHelper) + .then(this.parseRequirements) .then(this.packRequirements) .then(this.linkRequirements); @@ -218,6 +246,7 @@ class ServerlessPythonRequirements { 'after:deploy:function:packageFunction': after, 'requirements:install:install': () => BbPromise.bind(this) .then(this.addVendorHelper) + .then(this.parseRequirements) .then(this.packRequirements), 'requirements:clean:clean': () => BbPromise.bind(this) .then(this.cleanup)