Skip to content

Adds option to leave python libraries out of the deployment #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2017

Conversation

medwig
Copy link

@medwig medwig commented Jun 12, 2017

Solves the issue of unnecessarily packaging libraries that are required but included by default by the cloud provider - such as boto3 by AWS.

Done on a line-by-line basis by adding a #no-deploy comment beside the desired library in requirements.txt. Creates a parsed .requirements.txt file and re-targets pip install to that file.

example:

$ cat requirements.txt  
requests    
boto3 #no-deploy
pandas

…-by-line basis by adding a #no-deploy comment beside it in requirements.txt. Creates a parsed .requirements.txt file and retargets pip install to that file.
@dschep
Copy link
Contributor

dschep commented Jun 13, 2017

neat suggestion. probably a good enough solution for #14 as well. We're super busy at @unitedincome right now, so I'll look at this when I actually have time.

this.serverless.cli.log(
`Parsing Python requirements.txt`);

var fs = require('fs');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use fs-extra which is already imported as fse.

`Parsing Python requirements.txt`);

var fs = require('fs');
var reqs = fs.readFileSync("requirements.txt").toString().split('\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const please.

var fs = require('fs');
var reqs = fs.readFileSync("requirements.txt").toString().split('\n');

var newReqs = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let please.

var reqs = fs.readFileSync("requirements.txt").toString().split('\n');

var newReqs = ''
for (var i in reqs) {
Copy link
Contributor

@dschep dschep Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (.. of ..) and template strings and triple equal:

for (const req of reqs) {
  if (req.indexOf('#no-deploy') === -1) {
    newReqs += `${req}\n`;
  }
}

newReqs += reqs[i] + '\n'
}
}
fs.writeFileSync(".requirements.txt", newReqs, 'utf8');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build tools should use mktemp to avoid clobbering existing files whenever possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(BTW, just using mktemp as an example, you obviously can't write this into /tmp and have it be visible.)

@dschep dschep merged commit b9f436c into serverless:master Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants