-
Notifications
You must be signed in to change notification settings - Fork 293
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
Conversation
…-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.
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'); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 = '' |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
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: