From bcaab7890891b4fdf19062e79d3b4d1893a524a8 Mon Sep 17 00:00:00 2001 From: Robert Nishihara Date: Wed, 31 May 2017 17:30:46 -0700 Subject: [PATCH] Add script for building MacOS wheels. (#601) * Add script for building MacOS wheels. * Small cleanups to script. * Fix setting of PATH before building wheel. * Create symbolic link to correct Python executable so Ray installation finds the right Python. * Address comments. * Rename readme. --- ...anylinux1.md => README-building-wheels.md} | 13 +++- python/build-wheel-macos.sh | 65 +++++++++++++++++++ test/jenkins_tests/run_multi_node_tests.sh | 2 +- 3 files changed, 78 insertions(+), 2 deletions(-) rename python/{README-manylinux1.md => README-building-wheels.md} (59%) create mode 100755 python/build-wheel-macos.sh diff --git a/python/README-manylinux1.md b/python/README-building-wheels.md similarity index 59% rename from python/README-manylinux1.md rename to python/README-building-wheels.md index f8055d19d..9ad0ceda7 100644 --- a/python/README-manylinux1.md +++ b/python/README-building-wheels.md @@ -6,10 +6,21 @@ repository, including both changes to tracked files, and ANY untracked files. It will also cause all files inside the repository to be owned by root, and produce .whl files owned by root. -Inside the root directory (i.e. one level above this python directory), run +Inside the root directory (i.e., one level above this python directory), run ``` docker run --rm -w /ray -v `pwd`:/ray -ti quay.io/xhochy/arrow_manylinux1_x86_64_base:ARROW-1024 /ray/python/build-wheel-manylinux1.sh ``` The wheel files will be placed in the .whl directory. + +## Building MacOS wheels + +To build wheels for MacOS, run the following inside the root directory (i.e., +one level above this python directory). + +``` +./python/build-wheel-macos.sh +``` + +The script uses `sudo` multiple times, so you may need to type in a password. diff --git a/python/build-wheel-macos.sh b/python/build-wheel-macos.sh new file mode 100755 index 000000000..14b1f0c29 --- /dev/null +++ b/python/build-wheel-macos.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Cause the script to exit if a single command fails. +set -e + +# Show explicitly which commands are currently running. +set -x + +# Much of this is taken from https://github.com/matthew-brett/multibuild. +# This script uses "sudo", so you may need to type in a password a couple times. + +MACPYTHON_URL=https://www.python.org/ftp/python +MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions +DOWNLOAD_DIR=python_downloads + +PY_VERSIONS=("2.7.13" + "3.4.4" + "3.5.3" + "3.6.1") +PY_INSTS=("python-2.7.13-macosx10.6.pkg" + "python-3.4.4-macosx10.6.pkg" + "python-3.5.3-macosx10.6.pkg" + "python-3.6.1-macosx10.6.pkg") +PY_MMS=("2.7" + "3.4" + "3.5" + "3.6") + +mkdir -p $DOWNLOAD_DIR +mkdir -p .whl + +for ((i=0; i<${#PY_VERSIONS[@]}; ++i)); do + PY_VERSION=${PY_VERSIONS[i]} + PY_INST=${PY_INSTS[i]} + PY_MM=${PY_MMS[i]} + + # The -f flag is passed twice to also run git clean in the arrow subdirectory. + # The -d flag removes directories. The -x flag ignores the .gitignore file, + # and the -e flag ensures that we don't remove the .whl directory. + git clean -f -f -x -d -e .whl -e $DOWNLOAD_DIR + + # Install Python. + INST_PATH=python_downloads/$PY_INST + curl $MACPYTHON_URL/$PY_VERSION/$PY_INST > $INST_PATH + sudo installer -pkg $INST_PATH -target / + + # Create a link from "python" to the actual Python executable so that the + # Python on the path that Ray finds is the correct version. + if [ ! -e $MACPYTHON_PY_PREFIX/$PY_MM/bin/python ]; then + ln -s $MACPYTHON_PY_PREFIX/$PY_MM/bin/python$PY_MM $MACPYTHON_PY_PREFIX/$PY_MM/bin/python + fi + PYTHON_EXE=$MACPYTHON_PY_PREFIX/$PY_MM/bin/python + PIP_CMD="$(dirname $PYTHON_EXE)/pip$PY_MM" + + pushd python + # Fix the numpy version because this will be the oldest numpy version we can + # support. + $PIP_CMD install numpy==1.10.4 + # Install wheel to avoid the error "invalid command 'bdist_wheel'". + $PIP_CMD install wheel + # Add the correct Python to the path and build the wheel. + PATH=$MACPYTHON_PY_PREFIX/$PY_MM/bin:$PATH $PYTHON_EXE setup.py bdist_wheel + mv dist/*.whl ../.whl/ + popd +done diff --git a/test/jenkins_tests/run_multi_node_tests.sh b/test/jenkins_tests/run_multi_node_tests.sh index 91c9884b1..757c419cc 100755 --- a/test/jenkins_tests/run_multi_node_tests.sh +++ b/test/jenkins_tests/run_multi_node_tests.sh @@ -3,7 +3,7 @@ # Cause the script to exit if a single command fails. set -e -# show explicitly which commands are currently running +# Show explicitly which commands are currently running. set -x ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)