2020-03-30 18:44:54 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-12 14:08:32 -04:00
|
|
|
const {
|
|
|
|
|
execute,
|
|
|
|
|
docker,
|
|
|
|
|
clean,
|
|
|
|
|
resolve,
|
|
|
|
|
getarg,
|
|
|
|
|
bash,
|
|
|
|
|
python_image,
|
|
|
|
|
} = require("./script_utils.js");
|
2020-03-30 18:44:54 -04:00
|
|
|
const fs = require("fs-extra");
|
2020-05-21 10:36:36 -04:00
|
|
|
const IS_DOCKER = process.env.PSP_DOCKER;
|
2020-06-23 18:59:40 -04:00
|
|
|
const IS_MACOS = getarg("--macos");
|
2021-10-14 00:32:34 -04:00
|
|
|
const PYTHON = getarg("--python39")
|
2021-09-12 14:08:32 -04:00
|
|
|
? "python3.9"
|
|
|
|
|
: getarg("--python38")
|
|
|
|
|
? "python3.8"
|
|
|
|
|
: getarg("--python36")
|
|
|
|
|
? "python3.6"
|
|
|
|
|
: "python3.7";
|
2020-06-22 10:15:40 -04:00
|
|
|
|
|
|
|
|
let IMAGE = "manylinux2014";
|
2020-06-23 18:59:40 -04:00
|
|
|
let MANYLINUX_VERSION;
|
2020-06-22 10:15:40 -04:00
|
|
|
|
|
|
|
|
if (IS_DOCKER) {
|
2021-10-14 00:32:34 -04:00
|
|
|
// switch to 2014 only on python3
|
|
|
|
|
MANYLINUX_VERSION = getarg("--manylinux2010")
|
|
|
|
|
? "manylinux2010"
|
|
|
|
|
: getarg("--manylinux2014")
|
|
|
|
|
? "manylinux2014"
|
|
|
|
|
: "manylinux2014";
|
2020-06-22 10:15:40 -04:00
|
|
|
IMAGE = python_image(MANYLINUX_VERSION, PYTHON);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 18:44:54 -04:00
|
|
|
/**
|
|
|
|
|
* Using Perspective's docker images, create a wheel built for the image
|
2020-06-23 18:59:40 -04:00
|
|
|
* architecture and output it to the local filesystem. A thin wrapper around
|
|
|
|
|
* `bdist_wheel`, except it also automatically calls `auditwheel` (Linux) or
|
|
|
|
|
* `delocate` on Mac.
|
2020-03-30 18:44:54 -04:00
|
|
|
*/
|
|
|
|
|
try {
|
|
|
|
|
console.log("Copying assets to `dist` folder");
|
|
|
|
|
const dist = resolve`${__dirname}/../python/perspective/dist`;
|
|
|
|
|
const cpp = resolve`${__dirname}/../cpp/perspective`;
|
|
|
|
|
const lic = resolve`${__dirname}/../LICENSE`;
|
|
|
|
|
const cmake = resolve`${__dirname}/../cmake`;
|
|
|
|
|
const dcmake = resolve`${dist}/cmake`;
|
|
|
|
|
const dlic = resolve`${dist}/LICENSE`;
|
|
|
|
|
const obj = resolve`${dist}/obj`;
|
|
|
|
|
|
|
|
|
|
fs.mkdirpSync(dist);
|
|
|
|
|
fs.copySync(cpp, dist, {preserveTimestamps: true});
|
|
|
|
|
fs.copySync(lic, dlic, {preserveTimestamps: true});
|
|
|
|
|
fs.copySync(cmake, dcmake, {preserveTimestamps: true});
|
|
|
|
|
clean(obj);
|
|
|
|
|
|
2021-10-14 00:32:34 -04:00
|
|
|
let cmd = bash``;
|
2020-03-30 18:44:54 -04:00
|
|
|
|
|
|
|
|
// Create a wheel
|
2020-06-29 19:29:36 -04:00
|
|
|
if (MANYLINUX_VERSION) {
|
2020-08-26 11:57:39 -04:00
|
|
|
// install deps
|
2021-01-05 13:06:43 -05:00
|
|
|
|
2021-01-15 16:38:01 -05:00
|
|
|
// These are system deps that may only be in place from pep-517/518 so
|
|
|
|
|
// lets reinstall them to be sure
|
2021-02-25 18:16:40 -05:00
|
|
|
cmd += `${PYTHON} -m pip install -U 'numpy>=1.13.1' wheel twine && `;
|
2020-08-26 14:10:58 -04:00
|
|
|
|
2021-01-05 13:06:43 -05:00
|
|
|
// remove the build folder so we completely rebuild (and pick up the
|
2020-08-26 14:10:58 -04:00
|
|
|
// libs we just installed above, since this build method won't use
|
|
|
|
|
// pep-517/518)
|
2020-08-26 13:45:52 -04:00
|
|
|
cmd += `rm -rf build/ &&`;
|
2020-08-26 14:10:58 -04:00
|
|
|
|
|
|
|
|
// now build the wheel in place
|
2021-12-16 16:08:55 -05:00
|
|
|
cmd += `${PYTHON} setup.py build_ext bdist_wheel`;
|
2020-08-26 14:10:58 -04:00
|
|
|
|
2020-06-23 18:59:40 -04:00
|
|
|
// Use auditwheel on Linux - repaired wheels are in
|
|
|
|
|
// `python/perspective/wheelhouse`.
|
2020-06-29 19:29:36 -04:00
|
|
|
let PYTHON_INTERPRETER = PYTHON;
|
|
|
|
|
cmd += `&& ${PYTHON_INTERPRETER} -m auditwheel -v show ./dist/*.whl && ${PYTHON_INTERPRETER} -m auditwheel -v repair -L .lib ./dist/*.whl`;
|
2020-06-23 18:59:40 -04:00
|
|
|
} else if (IS_MACOS) {
|
2021-01-15 16:38:01 -05:00
|
|
|
// Don't need to do any cleaning here since we will reuse the cmake
|
|
|
|
|
// cache and numpy paths from the pep-517/518 build in build_python.js
|
2021-12-16 16:08:55 -05:00
|
|
|
cmd += `${PYTHON} setup.py build_ext bdist_wheel`;
|
2020-06-26 17:57:16 -04:00
|
|
|
cmd += " && mkdir -p ./wheelhouse && cp -v ./dist/*.whl ./wheelhouse";
|
2020-08-26 11:57:39 -04:00
|
|
|
} else {
|
2021-06-16 13:02:27 +08:00
|
|
|
// Windows
|
2021-12-16 16:08:55 -05:00
|
|
|
cmd += `${PYTHON} setup.py build_ext bdist_wheel`;
|
2020-05-21 10:36:36 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-23 18:59:40 -04:00
|
|
|
// TODO: MacOS wheel processed with delocate segfaults on
|
|
|
|
|
// `import perspective`.
|
|
|
|
|
|
2020-05-21 10:36:36 -04:00
|
|
|
if (IS_DOCKER) {
|
2021-09-12 14:08:32 -04:00
|
|
|
console.log(
|
|
|
|
|
`Building wheel for \`perspective-python\` using image \`${IMAGE}\` in Docker`
|
|
|
|
|
);
|
2020-05-21 10:36:36 -04:00
|
|
|
execute`${docker(IMAGE)} bash -c "cd python/perspective && ${cmd}"`;
|
|
|
|
|
} else {
|
2020-06-23 18:59:40 -04:00
|
|
|
console.log(`Building wheel for \`perspective-python\``);
|
2020-05-21 10:36:36 -04:00
|
|
|
const python_path = resolve`${__dirname}/../python/perspective`;
|
|
|
|
|
execute`cd ${python_path} && ${cmd}`;
|
|
|
|
|
}
|
2020-03-30 18:44:54 -04:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e.message);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|