Skip to content

Commit 69e7d34

Browse files
committed
require curlys to avoid the types of bugs @abetomo keeps finding
1 parent d33f082 commit 69e7d34

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ parserOptions:
44
rules:
55
no-console: 2
66
max-len: [1, 100, 2, {ignoreComments: true}]
7+
curly: error

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ class ServerlessPythonRequirements {
4242
'setuptools',
4343
],
4444
}, this.serverless.service.custom && this.serverless.service.custom.pythonRequirements || {});
45-
if (options.dockerizePip === 'non-linux')
45+
if (options.dockerizePip === 'non-linux') {
4646
options.dockerizePip = process.platform !== 'linux';
47+
}
4748
return options;
4849
}
4950

lib/link.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@ const rimraf = require('rimraf');
1212
*/
1313
function linkRequirements() {
1414
const requirementsDir = path.join(this.servicePath, '.serverless/requirements');
15-
if (fse.existsSync('__pycache__'))
15+
if (fse.existsSync('__pycache__')) {
1616
rimraf.sync('__pycache__');
17-
if (!get(this.serverless.service, 'package.include'))
17+
}
18+
if (!get(this.serverless.service, 'package.include')) {
1819
set(this.serverless.service, ['package', 'include'], []);
20+
}
1921
if (!this.options.zip && fse.existsSync(requirementsDir)) {
2022
this.serverless.cli.log('Linking required Python packages...');
2123
const noDeploy = new Set(this.options.noDeploy || []);
2224
fse.readdirSync(requirementsDir).map((file) => {
23-
if (noDeploy.has(file))
25+
if (noDeploy.has(file)) {
2426
return;
27+
}
2528
if (this.serverless.service.package.individually) {
2629
// don't include python deps in non-python functions
2730
values(this.serverless.service.functions)
2831
.filter((f) => (f.runtime || this.serverless.service.provider.runtime).match(/^python.*/))
2932
.forEach((f) => {
30-
if (!get(f, 'package.include'))
33+
if (!get(f, 'package.include')) {
3134
set(f, ['package', 'include'], []);
35+
}
3236
f.package.include.push(file);
3337
f.package.include.push(`${file}/**`);
3438
});
@@ -47,8 +51,9 @@ function linkRequirements() {
4751
linkDest = fse.readlinkSync(`./${file}`);
4852
} catch (e) {
4953
}
50-
if (linkDest !== `${requirementsDir}/${file}`)
54+
if (linkDest !== `${requirementsDir}/${file}`) {
5155
throw exception;
56+
}
5257
}
5358
}
5459
});
@@ -65,8 +70,9 @@ function unlinkRequirements() {
6570
this.serverless.cli.log('Unlinking required Python packages...');
6671
const noDeploy = new Set(this.options.noDeploy || []);
6772
fse.readdirSync(requirementsDir).map((file) => {
68-
if (noDeploy.has(file))
73+
if (noDeploy.has(file)) {
6974
return;
75+
}
7076
fse.unlinkSync(file);
7177
});
7278
}

lib/pip.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ function installRequirements() {
1414
fileName = dotSlsReqs;
1515
}
1616

17-
if (!fse.existsSync(path.join(this.servicePath, fileName)))
17+
if (!fse.existsSync(path.join(this.servicePath, fileName))) {
1818
return;
19+
}
1920

2021
this.serverless.cli.log(`Installing required Python packages with ${this.options.pythonBin}...`);
2122

@@ -39,13 +40,15 @@ function installRequirements() {
3940
const pipTestRes = spawnSync(
4041
this.options.pythonBin, ['-m', 'pip', 'help', 'install']);
4142
if (pipTestRes.error) {
42-
if (pipTestRes.error.code === 'ENOENT')
43+
if (pipTestRes.error.code === 'ENOENT') {
4344
throw new Error(`${this.options.pythonBin} not found! ` +
4445
'Try the pythonBin option.');
46+
}
4547
throw new Error(pipTestRes.error);
4648
}
47-
if (pipTestRes.stdout.toString().indexOf('--system') >= 0)
49+
if (pipTestRes.stdout.toString().indexOf('--system') >= 0) {
4850
pipCmd.push('--system');
51+
}
4952
}
5053
if (this.options.dockerizePip) {
5154
cmd = 'docker';
@@ -114,8 +117,9 @@ function installRequirements() {
114117
}
115118
throw new Error(res.error);
116119
}
117-
if (res.status !== 0)
120+
if (res.status !== 0) {
118121
throw new Error(res.stderr);
122+
}
119123
};
120124

121125
module.exports = {installRequirements};

lib/pipenv.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ const {spawnSync} = require('child_process');
66
* pipenv install
77
*/
88
function pipfileToRequirements() {
9-
if (!this.options.usePipenv || !fse.existsSync(path.join(this.servicePath, 'Pipfile')))
9+
if (!this.options.usePipenv || !fse.existsSync(path.join(this.servicePath, 'Pipfile'))) {
1010
return;
11+
}
1112

1213
this.serverless.cli.log('Generating requirements.txt from Pipfile...');
1314

1415
const res = spawnSync('pipenv', ['lock', '--requirements'], {cwd: this.servicePath});
1516
if (res.error) {
16-
if (res.error.code === 'ENOENT')
17+
if (res.error.code === 'ENOENT') {
1718
throw new Error(`pipenv not found! Install it with 'pip install pipenv'.`);
19+
}
1820
throw new Error(res.error);
1921
}
20-
if (res.status !== 0)
22+
if (res.status !== 0) {
2123
throw new Error(res.stderr);
24+
}
2225
fse.ensureDirSync(path.join(this.servicePath, '.serverless'));
2326
fse.writeFileSync(path.join(this.servicePath, '.serverless/requirements.txt'), res.stdout);
2427
};

lib/zip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ function addVendorHelper() {
1515
if (this.options.zip) {
1616
this.serverless.cli.log('Adding Python requirements helper...');
1717

18-
if (!get(this.serverless.service, 'package.include'))
18+
if (!get(this.serverless.service, 'package.include')) {
1919
set(this.serverless.service, ['package', 'include'], []);
20+
}
2021

2122
this.serverless.service.package.include.push('unzip_requirements.py');
2223

0 commit comments

Comments
 (0)