-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
var newReqs = '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for (var i in reqs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if(reqs[i].indexOf('#no-deploy') == -1) { | ||
newReqs += reqs[i] + '\n' | ||
} | ||
} | ||
fs.writeFileSync(".requirements.txt", newReqs, 'utf8'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build tools should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (BTW, just using |
||
|
||
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) | ||
|
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 asfse
.