Skip to content

Commit eaf1b78

Browse files
authored
honor escaped newlines in requirements.txt (serverless#264)
* test proving bug serverless#261 with pip-tools * honor escaped newlines in requirements.txt fixes serverless#261 * fix merge issue
1 parent e06c829 commit eaf1b78

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
# other deps
2525
- run: sudo apt -y update && sudo apt -y install python-pip python2.7 curl unzip
2626
# instal pipenv
27-
- run: sudo python3.6 -m pip install pipenv
27+
- run: sudo python3.6 -m pip install pipenv pip-tools
2828
# install nodejs
2929
- run: curl -sL https://deb.nodesource.com/setup_6.x | sudo bash - && sudo apt -y install nodejs
3030
# install serverless & depcheck

lib/pip.js

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ function generateRequirementsFile(source, target, options) {
297297
const noDeploy = new Set(options.noDeploy || []);
298298
const requirements = fse
299299
.readFileSync(source, { encoding: 'utf-8' })
300+
.replace(/\\\n/g, ' ')
300301
.split(/\r?\n/);
301302
var prepend = [];
302303
const filteredRequirements = requirements.filter(req => {

test.bats

+10-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ teardown() {
3535
ls puck/flask
3636
}
3737

38+
@test "py3.6 can package flask with hashes" {
39+
cd tests/base
40+
npm i $(npm pack ../..)
41+
pip-compile --output-file requirements-w-hashes.txt --generate-hashes requirements.txt
42+
sls package --fileName requirements-w-hashes.txt
43+
unzip .serverless/sls-py-req-test.zip -d puck
44+
ls puck/flask
45+
}
46+
3847
@test "py3.6 can package flask & bottle with zip option" {
3948
cd tests/base
4049
npm i $(npm pack ../..)
@@ -580,11 +589,8 @@ teardown() {
580589
@test "py3.6 supports custom file name with fileName option" {
581590
cd tests/base
582591
npm i $(npm pack ../..)
583-
docker &> /dev/null || skip "docker not present"
584-
! uname -sm|grep Linux || groups|grep docker || id -u|egrep '^0$' || skip "can't dockerize on linux if not root & not in docker group"
585-
perl -p -i'.bak' -e 's/(pythonRequirements:$)/\1\n fileName: puck/' serverless.yml
586592
echo "requests" > puck
587-
sls package
593+
sls --fileName puck package
588594
ls .serverless/requirements/requests
589595
! ls .serverless/requirements/flask
590596
}

tests/base/serverless.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ custom:
1313
slim: ${opt:slim, self:custom.defaults.slim}
1414
slimPatterns: ${file(./slimPatterns.yml):slimPatterns, self:custom.defaults.slimPatterns}
1515
vendor: ${opt:vendor, ''}
16+
fileName: ${opt:fileName, 'requirements.txt'}
1617
defaults:
1718
slim: false
1819
slimPatterns: false

0 commit comments

Comments
 (0)