Repository navigation
Expand file tree
/
Copy pathmacpython-build-wheels.sh
More file actions
executable file
·175 lines (152 loc) · 6.15 KB
/
Copy pathmacpython-build-wheels.sh
File metadata and controls
executable file
·175 lines (152 loc) · 6.15 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
# Run this script to build the ITK Python wheel packages for macOS.
#
# Versions can be restricted by passing them in as arguments to the script
# For example,
#
# scripts/macpython-build-wheels.sh 2.7 3.5
# -----------------------------------------------------------------------
# These variables are set in common script:
#
MACPYTHON_PY_PREFIX=""
PYBINARIES=""
PYTHON_LIBRARY=""
SCRIPT_DIR=""
script_dir=$(cd $(dirname $0) || exit 1; pwd)
source "${script_dir}/macpython-build-common.sh"
# -----------------------------------------------------------------------
# Remove previous virtualenv's
rm -rf ${SCRIPT_DIR}/../venvs
# Create virtualenv's
VENVS=()
mkdir -p ${SCRIPT_DIR}/../venvs
for PYBIN in "${PYBINARIES[@]}"; do
if [[ $(basename $PYBIN) = "Current" ]]; then
continue
fi
py_mm=$(basename ${PYBIN})
VENV=${SCRIPT_DIR}/../venvs/${py_mm}
VIRTUALENV_EXECUTABLE=${PYBIN}/bin/virtualenv
${VIRTUALENV_EXECUTABLE} ${VENV}
VENVS+=(${VENV})
done
VENV="${VENVS[0]}"
PYTHON_EXECUTABLE=${VENV}/bin/python
${PYTHON_EXECUTABLE} -m pip install --no-cache cmake
CMAKE_EXECUTABLE=${VENV}/bin/cmake
${PYTHON_EXECUTABLE} -m pip install --no-cache ninja
NINJA_EXECUTABLE=${VENV}/bin/ninja
${PYTHON_EXECUTABLE} -m pip install --no-cache delocate
DELOCATE_LISTDEPS=${VENV}/bin/delocate-listdeps
DELOCATE_WHEEL=${VENV}/bin/delocate-wheel
# Build standalone project and populate archive cache
mkdir -p standalone-build
pushd standalone-build > /dev/null 2>&1
${CMAKE_EXECUTABLE} -DITKPythonPackage_BUILD_PYTHON:PATH=0 \
-G Ninja \
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
${SCRIPT_DIR}/../
${NINJA_EXECUTABLE}
popd > /dev/null 2>&1
SINGLE_WHEEL=0
# Compile wheels re-using standalone project and archive cache
for VENV in "${VENVS[@]}"; do
py_mm=$(basename ${VENV})
PYTHON_EXECUTABLE=${VENV}/bin/python
PYTHON_INCLUDE_DIR=$( find -L ${MACPYTHON_PY_PREFIX}/${py_mm}/include -name Python.h -exec dirname {} \; )
echo ""
echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}"
echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}"
echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}"
# Install dependencies
${PYTHON_EXECUTABLE} -m pip install --upgrade -r ${SCRIPT_DIR}/../requirements-dev.txt
build_type="MinSizeRel"
plat_name="macosx-10.6-x86_64"
osx_target="10.6"
source_path=${SCRIPT_DIR}/../standalone-build/ITK-source
build_path="${SCRIPT_DIR}/../ITK-${py_mm}-macosx_x86_64"
SETUP_PY_CONFIGURE="${script_dir}/setup_py_configure.py"
# Clean up previous invocations
rm -rf ${build_path}
if [[ ${SINGLE_WHEEL} == 1 ]]; then
echo "#"
echo "# Build single ITK wheel"
echo "#"
# Configure setup.py
${PYTHON_EXECUTABLE} ${SETUP_PY_CONFIGURE} "itk"
# Generate wheel
${PYTHON_EXECUTABLE} setup.py bdist_wheel --build-type ${build_type} --plat-name ${plat_name} -G Ninja -- \
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
-DITK_SOURCE_DIR:PATH= ${source_path} \
-DITK_BINARY_DIR:PATH=${build_path} \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
# Cleanup
${PYTHON_EXECUTABLE} setup.py clean
else
echo "#"
echo "# Build multiple ITK wheels"
echo "#"
# Build ITK python
(
mkdir -p ${build_path} \
&& cd ${build_path} \
&& cmake \
-DCMAKE_BUILD_TYPE:STRING=${build_type} \
-DITK_SOURCE_DIR:PATH=${source_path} \
-DITK_BINARY_DIR:PATH=${build_path} \
-DBUILD_TESTING:BOOL=OFF \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} \
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
-DWRAP_ITK_INSTALL_COMPONENT_PER_MODULE:BOOL=ON \
-DPY_SITE_PACKAGES_PATH:PATH=${SCRIPT_DIR}/../_skbuild/cmake-install \
-DITK_LEGACY_SILENT:BOOL=ON \
-DITK_WRAP_PYTHON:BOOL=ON \
-DITK_WRAP_PYTHON_LEGACY:BOOL=OFF \
-G Ninja \
${source_path} \
&& ninja\
|| exit 1
)
wheel_names=$(cat ${SCRIPT_DIR}/WHEEL_NAMES.txt)
for wheel_name in ${wheel_names}; do
# Configure setup.py
${PYTHON_EXECUTABLE} ${SETUP_PY_CONFIGURE} ${wheel_name}
# Generate wheel
${PYTHON_EXECUTABLE} setup.py bdist_wheel --build-type ${build_type} --plat-name ${plat_name} -G Ninja -- \
-DITK_SOURCE_DIR:PATH=${source_path} \
-DITK_BINARY_DIR:PATH=${build_path} \
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${osx_target} \
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-DITKPythonPackage_ITK_BINARY_REUSE:BOOL=ON \
-DITKPythonPackage_WHEEL_NAME:STRING=${wheel_name} \
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY} \
|| exit 1
# Cleanup
${PYTHON_EXECUTABLE} setup.py clean
done
fi
# Remove unnecessary files for building against ITK
find ${build_path} -name '*.cpp' -delete -o -name '*.xml' -delete
rm -rf ${build_path}/Wrapping/Generators/castxml*
find ${build_path} -name '*.o' -delete
done
${DELOCATE_LISTDEPS} ${SCRIPT_DIR}/../dist/*.whl # lists library dependencies
${DELOCATE_WHEEL} ${SCRIPT_DIR}/../dist/*.whl # copies library dependencies into wheel
# Install packages and test
for VENV in "${VENVS[@]}"; do
${VENV}/bin/pip install numpy
${VENV}/bin/pip install itk --no-cache-dir --no-index -f ${SCRIPT_DIR}/../dist
(cd $HOME && ${VENV}/bin/python -c 'import itk;')
(cd $HOME && ${VENV}/bin/python -c 'import itk; image = itk.Image[itk.UC, 2].New()')
(cd $HOME && ${VENV}/bin/python -c 'import itkConfig; itkConfig.LazyLoading = False; import itk;')
done