Skip to content

Commit e5421c0

Browse files
committed
Linux wheels: use build.sh
To reduce duplicated code, this removes 200+ lines.
1 parent d836abb commit e5421c0

8 files changed

Lines changed: 92 additions & 323 deletions

File tree

.github/workflows/macos.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ jobs:
5555
- name: Tests
5656
run: |
5757
pip3 install pytest
58-
mv pygit2 pygit2~
5958
pip3 install dist/fixed-wheels/pygit2-*.whl
6059
pytest
6160

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
before_install: []
3535
install: skip
3636
script: &docker-script
37-
- travis/build-all-manylinux-wheels.sh 1.1
37+
- travis/build-all-manylinux-wheels.sh
3838
- ls -alh dist
3939
before_deploy:
4040
- ls dist

build.sh

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@
4747
#
4848

4949
set -x # Print every command and variable
50-
set -e # Exit script on any command failure
51-
52-
# Arguments
53-
WHAT=${1:-inplace}
50+
set -e # Fail fast
5451

5552
# Variables
53+
ARCH=`uname -m`
54+
BUILD_STATIC=${BUILD_STATIC:-''}
55+
BUILD_TYPE=${BUILD_TYPE:-Debug}
5656
PYTHON=${PYTHON:-python3}
57-
PYTHON_VERSION=$($PYTHON -c "import platform; print(f'{platform.python_implementation()}-{platform.python_version()}')")
58-
PREFIX="${PREFIX:-$(pwd)/ci/$PYTHON_VERSION}"
57+
58+
PYTHON_TAG=$($PYTHON build_tag.py)
59+
PREFIX="${PREFIX:-$(pwd)/ci/$PYTHON_TAG}"
5960
export LDFLAGS="-Wl,-rpath,$PREFIX/lib"
6061

6162
# Linux or macOS
@@ -74,17 +75,32 @@ esac
7475
$PYTHON -m venv $PREFIX
7576
cd ci
7677

78+
# Install zlib
79+
# XXX Build libgit2 with USE_BUNDLED_ZLIB instead?
80+
if [ -n "$ZLIB_VERSION" ]; then
81+
FILENAME=zlib-$ZLIB_VERSION
82+
wget https://www.zlib.net/$FILENAME.tar.gz -N
83+
tar xf $FILENAME.tar.gz
84+
cd $FILENAME
85+
./configure --prefix=$PREFIX $([ $BUILD_STATIC ] && echo "--static" || echo "")
86+
make
87+
make install
88+
cd ..
89+
fi
90+
7791
# Install libssh2
7892
if [ -n "$LIBSSH2_VERSION" ]; then
7993
FILENAME=libssh2-$LIBSSH2_VERSION
8094
wget https://www.libssh2.org/download/$FILENAME.tar.gz -N
8195
tar xf $FILENAME.tar.gz
8296
cd $FILENAME
83-
./configure --prefix=$PREFIX --disable-static
84-
make
85-
make install
97+
cmake . \
98+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
99+
-DBUILD_EXAMPLES=OFF \
100+
-DBUILD_TESTING=OFF \
101+
-DBUILD_SHARED_LIBS=$([ $BUILD_STATIC ] && echo "OFF" || echo "ON")
102+
cmake --build . --target install
86103
cd ..
87-
$LDD $PREFIX/lib/libssh2.$SOEXT
88104
LIBSSH2_PREFIX=$PREFIX
89105
fi
90106

@@ -94,7 +110,11 @@ if [ -n "$LIBGIT2_VERSION" ]; then
94110
wget https://github.com/libgit2/libgit2/releases/download/v$LIBGIT2_VERSION/$FILENAME.tar.gz -N
95111
tar xf $FILENAME.tar.gz
96112
cd $FILENAME
97-
CMAKE_PREFIX_PATH=$OPENSSL_PREFIX:$LIBSSH2_PREFIX cmake . -DBUILD_CLAR=OFF -DCMAKE_INSTALL_PREFIX=$PREFIX
113+
CMAKE_PREFIX_PATH=$OPENSSL_PREFIX:$LIBSSH2_PREFIX cmake . \
114+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
115+
-DBUILD_CLAR=OFF \
116+
-DBUILD_SHARED_LIBS=$([ $BUILD_STATIC ] && echo "OFF" || echo "ON") \
117+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
98118
cmake --build . --target install
99119
cd ..
100120
$LDD $PREFIX/lib/libgit2.$SOEXT
@@ -104,18 +124,32 @@ fi
104124
# Build pygit2
105125
cd ..
106126
$PREFIX/bin/pip install -U pip
107-
if [ $WHAT = "wheel" ]; then
127+
if [ "$1" = "wheel" ]; then
128+
shift
108129
$PREFIX/bin/pip install wheel
109130
$PREFIX/bin/python setup.py bdist_wheel
131+
WHEELDIR=dist
110132
else
111133
# Install Python requirements & build inplace
112134
$PREFIX/bin/python setup.py egg_info
113135
$PREFIX/bin/pip install -r pygit2.egg-info/requires.txt
114136
$PREFIX/bin/python setup.py build_ext --inplace
115137
fi
116138

139+
# Bundle libraries
140+
if [ "$1" = "bundle" ]; then
141+
shift
142+
$PREFIX/bin/pip install auditwheel
143+
$PREFIX/bin/auditwheel repair dist/pygit2*-$PYTHON_TAG-*_$ARCH.whl
144+
$PREFIX/bin/auditwheel show wheelhouse/pygit2*-$PYTHON_TAG-*_$ARCH.whl
145+
WHEELDIR=wheelhouse
146+
fi
147+
117148
# Tests
118-
if [ $WHAT = "test" ]; then
149+
if [ "$1" = "test" ]; then
150+
if [ -n "$WHEELDIR" ]; then
151+
$PREFIX/bin/pip install $WHEELDIR/pygit2*-$PYTHON_TAG-*_$ARCH.whl
152+
fi
119153
$PREFIX/bin/pip install -r requirements-test.txt
120154
$PREFIX/bin/pytest --cov=pygit2
121155
fi

build_tag.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import platform, sys
2+
3+
py = {'CPython': 'cp', 'PyPy': 'pp'}[platform.python_implementation()]
4+
print(f'{py}{sys.version_info.major}{sys.version_info.minor}')

test/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@
2222
# along with this program; see the file COPYING. If not, write to
2323
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2424
# Boston, MA 02110-1301, USA.
25+
26+
# Move the current directory to the end of the list of import paths. This way
27+
# we avoid the "ModuleNotFoundError: No module named 'pygit2._pygit2'" error
28+
# when running the test suite in Continuous Integration.
29+
import os
30+
import sys
31+
cwd = os.getcwd()
32+
sys.path.remove(cwd)
33+
sys.path.append(cwd)

test/test_packbuilder.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import pygit2
3333
from pygit2 import PackBuilder
3434
from . import utils
35-
from .utils import rmtree
3635

3736

3837
def test_create_packbuilder(testrepo):
@@ -92,7 +91,7 @@ def confirm_same_repo_after_packing(testrepo, tmp_path, pack_delegate):
9291
pack_repo = setup_second_repo(tmp_path)
9392

9493
objects_dir = os.path.join(pack_repo.path, 'objects')
95-
rmtree(objects_dir)
94+
utils.rmtree(objects_dir)
9695
pack_path = os.path.join(pack_repo.path, 'objects', 'pack')
9796
os.makedirs(pack_path)
9897

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
#! /usr/bin/env bash
2-
if [ -n "$DEBUG" ]
3-
then
4-
set -x
5-
fi
62

7-
LIBGIT2_VERSION="$1"
8-
9-
set -euo pipefail
10-
11-
if [ -z "$LIBGIT2_VERSION" ]
12-
then
13-
>&2 echo "Please pass libgit2 version as first argument of this script ($0)"
14-
exit 1
15-
fi
3+
set -x
4+
set -e
165

6+
# Wait for docker pull to complete downloading container
177
manylinux_image="ghcr.io/pyca/cryptography-manylinux2014:x86_64"
18-
19-
echo Waiting for docker pull to complete downloading container...
208
docker pull "${manylinux_image}" &
219
wait
2210

23-
echo Building wheel
24-
docker run --rm -v `pwd`:/io "${manylinux_image}" /io/travis/build-manylinux-wheels.sh pygit2 "$LIBGIT2_VERSION" &
11+
# Build wheels
12+
docker run --rm -v `pwd`:/io/src "${manylinux_image}" /io/src/travis/build-manylinux-wheels.sh &
2513
wait
26-
27-
set +u

0 commit comments

Comments
 (0)