forked from finos/perspective
/
ci_python.js
57 lines (50 loc) · 2.16 KB
/
ci_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
48
49
50
51
52
53
54
55
56
57
/******************************************************************************
*
* 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 fs = require("fs-extra");
const mkdir = require("mkdirp");
const rimraf = require("rimraf");
const execute = cmd => execSync(cmd, {stdio: "inherit"});
const PY2 = args.indexOf("--python2") != -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 {
// copy C++ assets
rimraf.sync(resolve(__dirname, "..", "python", "perspective", "obj")); // unused obj folder
fs.copySync(resolve(__dirname, "..", "cpp", "perspective"), resolve(__dirname, "..", "python", "perspective"), {overwrite: true});
mkdir(resolve(__dirname, "..", "python", "perspective", "cmake"));
fs.copySync(resolve(__dirname, "..", "cmake"), resolve(__dirname, "..", "python", "perspective", "cmake"), {overwrite: true});
let cmd;
let python = PY2 ? "python2" : "python3";
let image = PY2 ? "python2" : "python";
let build_cmd = `${python} -m pip install -r requirements-dev.txt &&\
${python} setup.py build &&\
${python} -m flake8 perspective && echo OK &&\
${python} -m pytest -v perspective --cov=perspective`;
if (process.env.PSP_DOCKER) {
cmd = `cd python/perspective && ${build_cmd}`;
execute(`${docker("perspective", image)} bash -c "${cmd}"`);
} else {
const python_path = resolve(__dirname, "..", "python", "perspective");
cmd = `cd ${python_path} && ${build_cmd}`;
execute(cmd);
}
} catch (e) {
console.log(e.message);
process.exit(1);
}