Skip to content

Commit 5e9eef2

Browse files
committed
macpython: add module wheels script
1 parent b785483 commit 5e9eef2

File tree

5 files changed

+114
-42
lines changed

5 files changed

+114
-42
lines changed

scripts/dockcross-manylinux-build-module-wheels.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#
66
# Versions can be restricted by passing them in as arguments to the script
77
# For example,
8-
# scripts/dockcross-manylinux-build-module-wheels.sh cp27mu cp35
8+
#
9+
# scripts/dockcross-manylinux-build-module-wheels.sh cp27mu cp35
910

1011
# Pull dockcross manylinux images
1112
docker pull dockcross/manylinux-x64

scripts/dockcross-manylinux-build-wheels.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#
55
# Versions can be restricted by passing them in as arguments to the script
66
# For example,
7-
# scripts/dockcross-manylinux-build-wheels.sh cp27mu cp35
7+
#
8+
# scripts/dockcross-manylinux-build-wheels.sh cp27mu cp35
89

910
# Pull dockcross manylinux images
1011
docker pull dockcross/manylinux-x64

scripts/macpython-build-common.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Content common to macpython-build-wheels.sh and
2+
# macpython-build-module-wheels.sh
3+
4+
set -e -x
5+
MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
6+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
7+
8+
# Versions can be restricted by passing them in as arguments to the script
9+
# For example,
10+
# macpython-build-wheels.sh 2.7 3.5
11+
if [[ $# -eq 0 ]]; then
12+
PYBINARIES=(${MACPYTHON_PY_PREFIX}/*)
13+
else
14+
PYBINARIES=()
15+
for version in "$@"; do
16+
PYBINARIES+=(${MACPYTHON_PY_PREFIX}/*${version}*)
17+
done
18+
fi
19+
20+
VENVS=()
21+
mkdir -p ${SCRIPT_DIR}/../venvs
22+
for PYBIN in "${PYBINARIES[@]}"; do
23+
if [[ $(basename $PYBIN) = "Current" ]]; then
24+
continue
25+
fi
26+
py_mm=$(basename ${PYBIN})
27+
VENV=${SCRIPT_DIR}/../venvs/${py_mm}
28+
VENVS+=(${VENV})
29+
done
30+
31+
VENV="${VENVS[0]}"
32+
PYTHON_EXECUTABLE=${VENV}/bin/python
33+
$PYTHON_EXECUTABLE -m pip install --no-cache cmake
34+
CMAKE_EXECUTABLE=${VENV}/bin/cmake
35+
$PYTHON_EXECUTABLE -m pip install --no-cache ninja
36+
NINJA_EXECUTABLE=${VENV}/bin/ninja
37+
$PYTHON_EXECUTABLE -m pip install --no-cache delocate
38+
DELOCATE_LISTDEPS=${VENV}/bin/delocate-listdeps
39+
DELOCATE_WHEEL=${VENV}/bin/delocate-wheel
40+
41+
42+
# Since the python interpreter exports its symbol (see [1]), python
43+
# modules should not link against any python libraries.
44+
# To ensure it is not the case, we configure the project using an empty
45+
# file as python library.
46+
#
47+
# [1] "Note that libpythonX.Y.so.1 is not on the list of libraries that
48+
# a manylinux1 extension is allowed to link to. Explicitly linking to
49+
# libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking
50+
# works, extension modules that are loaded into the interpreter automatically
51+
# get access to all of the interpreter's symbols, regardless of whether or
52+
# not the extension itself is explicitly linked against libpython. [...]"
53+
#
54+
# Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
55+
PYTHON_LIBRARY=$(cd $(dirname $0); pwd)/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter
56+
touch ${PYTHON_LIBRARY}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
3+
# Run this script to build the Python wheel packages for macOS for an ITK
4+
# external module.
5+
#
6+
# Versions can be restricted by passing them in as arguments to the script
7+
# For example,
8+
#
9+
# scripts/macpython-build-module-wheels.sh 2.7 3.5
10+
11+
script_dir="`cd $(dirname $0); pwd`"
12+
source "${script_dir}/macpython-build-common.sh"
13+
14+
# Compile wheels re-using standalone project and archive cache
15+
for VENV in "${VENVS[@]}"; do
16+
py_mm=$(basename ${VENV})
17+
PYTHON_EXECUTABLE=${VENV}/bin/python
18+
PYTHON_INCLUDE_DIR=$( find -L ${MACPYTHON_PY_PREFIX}/${py_mm}/include -name Python.h -exec dirname {} \; )
19+
20+
echo ""
21+
echo "PYTHON_EXECUTABLE:${PYTHON_EXECUTABLE}"
22+
echo "PYTHON_INCLUDE_DIR:${PYTHON_INCLUDE_DIR}"
23+
echo "PYTHON_LIBRARY:${PYTHON_LIBRARY}"
24+
25+
if [[ -e $PWD/requirements-dev.txt ]]; then
26+
$PYTHON_EXECUTABLE -m pip install -r $PWD/requirements-dev.txt
27+
fi
28+
$PYTHON_EXECUTABLE -m pip install --no-cache ninja
29+
NINJA_EXECUTABLE=${VENV}/bin/ninja
30+
itk_build_path="${SCRIPT_DIR}/../ITK-${py_mm}-macosx_x86_64"
31+
$PYTHON_EXECUTABLE setup.py bdist_wheel --build-type MinSizeRel --plat-name macosx-10.6-x86_64 -G Ninja -- \
32+
-DCMAKE_MAKE_PROGRAM:FILEPATH=${NINJA_EXECUTABLE} \
33+
-DITK_DIR:PATH=${itk_build_path} \
34+
-DITK_USE_SYSTEM_SWIG:BOOL=ON \
35+
-DWRAP_ITK_INSTALL_COMPONENT_IDENTIFIER:STRING=PythonWheel \
36+
-DSWIG_EXECUTABLE:FILEPATH=${itk_build_path}/Wrapping/Generators/SwigInterface/swig/bin/swig \
37+
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.6 \
38+
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
39+
-DBUILD_TESTING:BOOL=OFF \
40+
-DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE} \
41+
-DPYTHON_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR} \
42+
-DPYTHON_LIBRARY:FILEPATH=${PYTHON_LIBRARY}
43+
$PYTHON_EXECUTABLE setup.py clean
44+
done
45+
46+
$DELOCATE_LISTDEPS $PWD/dist/*.whl # lists library dependencies
47+
$DELOCATE_WHEEL $PWD/dist/*.whl # copies library dependencies into wheel

scripts/macpython-build-wheels.sh

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
#!/usr/bin/env bash
2-
set -e -x
3-
MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
4-
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
52

3+
# Run this script to build the ITK Python wheel packages for macOS.
4+
#
65
# Versions can be restricted by passing them in as arguments to the script
76
# For example,
8-
# macpython-build-wheels.sh 2.7 3.5
9-
if [[ $# -eq 0 ]]; then
10-
PYBINARIES=(${MACPYTHON_PY_PREFIX}/*)
11-
else
12-
PYBINARIES=()
13-
for version in "$@"; do
14-
PYBINARIES+=(${MACPYTHON_PY_PREFIX}/*${version}*)
15-
done
16-
fi
7+
#
8+
# scripts/macpython-build-wheels.sh 2.7 3.5
9+
10+
script_dir="`cd $(dirname $0); pwd`"
11+
source "${script_dir}/macpython-build-common.sh"
1712

1813
# Remove previous virtualenv's
1914
rm -rf ${SCRIPT_DIR}/../venvs
@@ -31,18 +26,6 @@ for PYBIN in "${PYBINARIES[@]}"; do
3126
VENVS+=(${VENV})
3227
done
3328

34-
# Install CMake, Ninja
35-
VENV="${VENVS[0]}"
36-
PYTHON_EXECUTABLE=${VENV}/bin/python
37-
$PYTHON_EXECUTABLE -m pip install cmake
38-
CMAKE_EXECUTABLE=${VENV}/bin/cmake
39-
$PYTHON_EXECUTABLE -m pip install ninja
40-
NINJA_EXECUTABLE=${VENV}/bin/ninja
41-
$PYTHON_EXECUTABLE -m pip install delocate
42-
DELOCATE_LISTDEPS=${VENV}/bin/delocate-listdeps
43-
DELOCATE_WHEEL=${VENV}/bin/delocate-wheel
44-
45-
4629
# Build standalone project and populate archive cache
4730
mkdir -p standalone-build
4831
pushd standalone-build > /dev/null 2>&1
@@ -53,22 +36,6 @@ pushd standalone-build > /dev/null 2>&1
5336
$NINJA_EXECUTABLE
5437
popd > /dev/null 2>&1
5538

56-
# Since the python interpreter exports its symbol (see [1]), python
57-
# modules should not link against any python libraries.
58-
# To ensure it is not the case, we configure the project using an empty
59-
# file as python library.
60-
#
61-
# [1] "Note that libpythonX.Y.so.1 is not on the list of libraries that
62-
# a manylinux1 extension is allowed to link to. Explicitly linking to
63-
# libpythonX.Y.so.1 is unnecessary in almost all cases: the way ELF linking
64-
# works, extension modules that are loaded into the interpreter automatically
65-
# get access to all of the interpreter's symbols, regardless of whether or
66-
# not the extension itself is explicitly linked against libpython. [...]"
67-
#
68-
# Source: https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
69-
PYTHON_LIBRARY=${SCRIPT_DIR}/internal/manylinux-libpython-not-needed-symbols-exported-by-interpreter
70-
touch ${PYTHON_LIBRARY}
71-
7239
# Compile wheels re-using standalone project and archive cache
7340
for VENV in "${VENVS[@]}"; do
7441
py_mm=$(basename ${VENV})

0 commit comments

Comments
 (0)