forked from perspective-dev/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_python.js
More file actions
133 lines (122 loc) · 4.17 KB
/
build_python.js
File metadata and controls
133 lines (122 loc) · 4.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/******************************************************************************
*
* 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 {
execute,
execute_throw,
docker,
resolve,
getarg,
bash,
python_image,
} = require("./script_utils.js");
const fs = require("fs-extra");
const IS_PY2 = getarg("--python2");
let PYTHON = IS_PY2
? "python2"
: getarg("--python38")
? "python3.8"
: getarg("--python36")
? "python3.6"
: "python3.7";
let IMAGE = "manylinux2010";
const IS_DOCKER = process.env.PSP_DOCKER;
if (IS_DOCKER) {
// defaults to 2010
let MANYLINUX_VERSION = "manylinux2010";
if (!IS_PY2) {
// switch to 2014 only on python3
(MANYLINUX_VERSION = getarg("--manylinux2010")
? "manylinux2010"
: getarg("--manylinux2014")
? "manylinux2014"
: "manylinux2010"),
PYTHON;
}
IMAGE = python_image(MANYLINUX_VERSION, PYTHON);
}
const IS_CI = getarg("--ci");
const SETUP_ONLY = getarg("--setup-only");
const IS_INSTALL = getarg("--install");
// Check that the `PYTHON` command is valid, else default to `python`.
try {
execute_throw`${PYTHON} --version`;
} catch (e) {
console.warn(`\`${PYTHON}\` not found - using \`python\` instead.`);
PYTHON = "python";
}
try {
const dist = resolve`${__dirname}/../python/perspective/dist`;
const cpp = resolve`${__dirname}/../cpp/perspective/src`;
const cmakelists = resolve`${__dirname}/../cpp/perspective/CMakeLists.txt`;
const lic = resolve`${__dirname}/../LICENSE`;
const cmake = resolve`${__dirname}/../cmake`;
const dcmake = resolve`${dist}/cmake`;
const dlic = resolve`${dist}/LICENSE`;
fs.mkdirpSync(dist);
fs.copySync(cmakelists, resolve`${dist}/CMakeLists.txt`, {
preserveTimestamps: true,
});
fs.copySync(cpp, resolve`${dist}/src`, {preserveTimestamps: true});
fs.copySync(lic, dlic, {preserveTimestamps: true});
fs.copySync(cmake, dcmake, {preserveTimestamps: true});
if (SETUP_ONLY) {
// don't execute any build steps, just copy
// the C++ assets into the python folder
return;
}
let cmd;
if (IS_CI) {
if (IS_PY2) {
// shutil_which is required in setup.py
cmd = bash`${PYTHON} -m pip install backports.shutil_which && ${PYTHON} -m pip install -e .[devpy2] --no-clean &&`;
} else {
cmd = bash`${PYTHON} -m pip install -e .[dev] --no-clean &&`;
}
// pip install in-place with --no-clean so that pep-518 assets stick
// around for later wheel build (so cmake cache can stay in place)
//
// lint the folder with flake8
//
// pytest the client first (since we need to move the shared libraries out of place
// temporarily to simulate them not being installed)
//
// then run the remaining test suite
cmd =
cmd +
`${PYTHON} -m flake8 perspective && echo OK && \
${PYTHON} -m pytest -vvv --noconftest perspective/tests/client_mode && \
${PYTHON} -m pytest -vvv perspective \
--ignore=perspective/tests/client_mode \
--junitxml=python_junit.xml --cov-report=xml --cov-branch \
--cov=perspective`;
if (IMAGE == "python") {
// test the sdist to make sure we dont
// dist a non-functioning source dist
cmd =
cmd +
`&& \
${PYTHON} setup.py sdist && \
${PYTHON} -m pip install -U dist/*.tar.gz`;
}
} else if (IS_INSTALL) {
cmd = `${PYTHON} -m pip install .`;
} else {
cmd = bash`${PYTHON} setup.py build -v`;
}
if (IS_DOCKER) {
execute`${docker(IMAGE)} bash -c "cd python/perspective && \
${cmd} "`;
} else {
const python_path = resolve`${__dirname}/../python/perspective`;
execute`cd ${python_path} && ${cmd}`;
}
} catch (e) {
console.log(e.message);
process.exit(1);
}