forked from finos/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint_python.js
47 lines (41 loc) · 1.63 KB
/
lint_python.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
const args = process.argv.slice(2);
const resolve = require("path").resolve;
const execSync = require("child_process").execSync;
const execute = cmd => execSync(cmd, {stdio: "inherit"});
const VALID_TARGETS = ["node", "table"];
const HAS_TARGET = args.indexOf("--target") != -1;
const IS_FIX = args.indexOf("--fix") != -1;
function docker(target = "perspective", image = "emsdk") {
console.log(`-- Creating ${image} docker image`);
let cmd = "docker run --rm -it";
if (process.env.PSP_CPU_COUNT) {
cmd += ` --cpus="${parseInt(process.env.PSP_CPU_COUNT)}.0"`;
}
cmd += ` -v $(pwd):/usr/src/app/python/${target} -w /usr/src/app/python/${target} perspective/${image}`;
return cmd;
}
try {
let cmd;
let lint_cmd = `python3 -m flake8 perspective && echo "lint passed!"`;
let fix_cmd = `autopep8 -v --in-place --aggressive --recursive --exclude build . &&\
echo "autopep8 formatting complete!"`;
if (process.env.PSP_DOCKER) {
cmd = `cd python/perspective && ${IS_FIX ? fix_cmd : lint_cmd}`;
execute(`${docker("perspective", "python")} bash -c "${cmd}"`);
} else {
const python_path = resolve(__dirname, "..", "python", "perspective");
cmd = `cd ${python_path} && ${IS_FIX ? fix_cmd : lint_cmd}`;
execute(cmd);
}
} catch (e) {
console.log(e);
process.exit(1);
}