Skip to content

Commit b694c3a

Browse files
committed
Use cibuildwheel to build release wheels
1 parent 5797936 commit b694c3a

File tree

6 files changed

+67
-167
lines changed

6 files changed

+67
-167
lines changed

.github/workflows/build-manylinux-wheels.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/install-postgres.sh

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,42 @@
33
set -Eexuo pipefail
44
shopt -s nullglob
55

6-
export DEBIAN_FRONTEND=noninteractive
6+
PGVERSION=${PGVERSION:-12}
77

8-
apt-get install -y --no-install-recommends curl
9-
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
10-
mkdir -p /etc/apt/sources.list.d/
11-
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${DISTRO_NAME}-pgdg main" \
12-
>> /etc/apt/sources.list.d/pgdg.list
13-
apt-get update
14-
apt-get install -y --no-install-recommends \
15-
postgresql-${PGVERSION} \
16-
postgresql-contrib-${PGVERSION}
8+
if [ -e /etc/os-release ]; then
9+
source /etc/os-release
10+
elif [ -e /etc/centos-release ]; then
11+
ID="centos"
12+
VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.)
13+
else
14+
echo "install-postgres.sh: cannot determine which Linux distro this is" >&2
15+
exit 1
16+
fi
17+
18+
if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
19+
export DEBIAN_FRONTEND=noninteractive
20+
21+
apt-get install -y --no-install-recommends curl gnupg ca-certificates
22+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
23+
mkdir -p /etc/apt/sources.list.d/
24+
echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \
25+
>> /etc/apt/sources.list.d/pgdg.list
26+
apt-get update
27+
apt-get install -y --no-install-recommends \
28+
"postgresql-${PGVERSION}" \
29+
"postgresql-contrib-${PGVERSION}"
30+
elif [ "${ID}" = "centos" ]; then
31+
el="EL-${VERSION_ID}-$(arch)"
32+
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
33+
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
34+
if [ ${VERSION_ID} -ge 8 ]; then
35+
dnf -qy module disable postgresql
36+
fi
37+
yum install -y \
38+
"postgresql${PGVERSION}-server" \
39+
"postgresql${PGVERSION}-contrib"
40+
ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config"
41+
else
42+
echo "install-postgres.sh: Unsupported distro: ${distro}" >&2
43+
exit 1
44+
fi

.github/workflows/release.yml

Lines changed: 21 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,16 @@ jobs:
6666
- uses: actions/upload-artifact@v2
6767
with:
6868
name: dist
69-
path: dist/
69+
path: dist/*.tar.*
7070

7171
build-wheels:
7272
needs: validate-release-request
7373
runs-on: ${{ matrix.os }}
7474
strategy:
7575
matrix:
76-
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0.rc.1]
7776
os: [ubuntu-latest, macos-latest, windows-latest]
78-
arch: [x86_64]
79-
exclude:
80-
- os: windows-latest
81-
arch: aarch64
82-
- os: macos-latest
83-
arch: aarch64
77+
cibw_python: ["cp37-*", "cp38-*", "cp39-*", "cp310-*"]
78+
cibw_arch: ["auto64"]
8479

8580
defaults:
8681
run:
@@ -95,121 +90,29 @@ jobs:
9590
fetch-depth: 50
9691
submodules: true
9792

98-
- name: Set up QEMU
99-
if: matrix.arch == 'aarch64'
100-
uses: docker/setup-qemu-action@v1
101-
102-
- name: Set up Python ${{ matrix.python-version }}
103-
uses: actions/setup-python@v2
104-
with:
105-
python-version: ${{ matrix.python-version }}
106-
107-
- name: Install Python Deps
108-
run: |
109-
python -m pip install --upgrade setuptools pip wheel
110-
111-
- name: Build Wheels (linux)
112-
if: startsWith(matrix.os, 'ubuntu')
93+
- uses: pypa/cibuildwheel@v2.1.1
11394
env:
114-
PYTHON_VERSION: ${{ matrix.python-version }}
115-
ARCH: ${{ matrix.arch }}
116-
run: |
117-
case "${ARCH}" in
118-
x86_64)
119-
mlimg=manylinux1_x86_64
120-
;;
121-
aarch64)
122-
mlimg=manylinux2014_aarch64
123-
;;
124-
*)
125-
echo "Unsupported wheel arch: ${ARCH}" >&2
126-
exit 1
127-
;;
128-
esac
129-
130-
docker run --rm \
131-
-v "${GITHUB_WORKSPACE}":/github/workspace:rw \
132-
--workdir=/github/workspace \
133-
-e GITHUB_WORKSPACE=/github/workspace \
134-
-e PYTHON_VERSION="${PYTHON_VERSION}" \
135-
--entrypoint=/github/workspace/.github/workflows/build-manylinux-wheels.sh \
136-
quay.io/pypa/${mlimg}
137-
138-
- name: Build Wheels (non-linux)
139-
if: "!startsWith(matrix.os, 'ubuntu')"
140-
run: |
141-
make clean
142-
python setup.py bdist_wheel
143-
144-
- name: Test Wheels (native)
145-
if: |
146-
!contains(github.event.pull_request.labels.*.name, 'skip wheel tests')
147-
&& matrix.arch == 'x86_64'
148-
env:
149-
OS: ${{ matrix.os }}
150-
run: |
151-
if [ "${OS}" = "windows-latest" ]; then
152-
export PGINSTALLATION="${PGBIN}"
153-
fi
154-
"${GITHUB_WORKSPACE}/.github/workflows/test-wheels.sh"
155-
156-
- name: Test Wheels (emulated)
157-
if: |
158-
!contains(github.event.pull_request.labels.*.name, 'skip wheel tests')
159-
&& matrix.arch != 'x86_64'
160-
env:
161-
PYTHON_VERSION: ${{ matrix.python-version }}
162-
PGVERSION: 13
163-
DISTRO_NAME: focal
164-
ARCH: ${{ matrix.arch }}
165-
run: |
166-
sudo env DISTRO_NAME="${DISTRO_NAME}" PGVERSION="${PGVERSION}" \
167-
.github/workflows/install-postgres.sh
168-
# Allow docker guest to connect to the database
169-
echo "port = 5433" | \
170-
sudo tee --append /etc/postgresql/${PGVERSION}/main/postgresql.conf
171-
echo "listen_addresses = '*'" | \
172-
sudo tee --append /etc/postgresql/${PGVERSION}/main/postgresql.conf
173-
echo "host all all 172.17.0.0/16 trust" | \
174-
sudo tee --append /etc/postgresql/${PGVERSION}/main/pg_hba.conf
175-
if [ "${PGVERSION}" -ge "11" ]; then
176-
# Disable JIT to avoid unpredictable timings in tests.
177-
echo "jit = off" | \
178-
sudo tee --append /etc/postgresql/${PGVERSION}/main/postgresql.conf
179-
fi
180-
sudo pg_ctlcluster ${PGVERSION} main restart
181-
182-
case "${ARCH}" in
183-
aarch64)
184-
img="docker.io/arm64v8/python:${PYTHON_VERSION}-buster"
185-
;;
186-
*)
187-
echo "Unsupported wheel arch: ${ARCH}" >&2
188-
exit 1
189-
;;
190-
esac
191-
192-
docker run --rm \
193-
-v "${GITHUB_WORKSPACE}":/github/workspace:rw \
194-
-e GITHUB_WORKSPACE=/github/workspace \
195-
-e PYTHON_VERSION="${PYTHON_VERSION}" \
196-
--workdir=/github/workspace/ \
197-
${img} \
198-
/bin/bash -ex -c ' \
199-
echo GITHUB_WORKSPACE=${GITHUB_WORKSPACE} >> /etc/environment \
200-
&& echo PGHOST=$(ip route | grep default | cut -f3 -d" " | uniq) \
201-
>> /etc/environment \
202-
&& echo PGPORT=5433 >> /etc/environment \
203-
&& echo PGUSER=postgres >> /etc/environment \
204-
&& echo ENVIRON_FILE /etc/environment >> /etc/login.defs \
205-
&& useradd -m -s /bin/bash test \
206-
&& su -l test /github/workspace/.github/workflows/test-wheels.sh \
207-
'
95+
CIBW_BUILD_VERBOSITY: 1
96+
CIBW_BUILD: ${{ matrix.cibw_python }}
97+
CIBW_ARCHS: ${{ matrix.cibw_arch }}
98+
CIBW_BEFORE_ALL_LINUX: >
99+
yum -y install libffi-devel
100+
&& env PGVERSION=12 .github/workflows/install-postgres.sh
101+
&& useradd -m -s /bin/bash apgtest
102+
CIBW_TEST_EXTRAS: "test"
103+
CIBW_TEST_COMMAND: >
104+
python {project}/tests/__init__.py
105+
CIBW_TEST_COMMAND_WINDOWS: >
106+
python {project}\tests\__init__.py
107+
CIBW_TEST_COMMAND_LINUX: >
108+
PY=`which python`
109+
&& chmod -R go+rX "$(dirname $(dirname $(dirname $PY)))"
110+
&& su -p -l apgtest -c "$PY {project}/tests/__init__.py"
208111
209112
- uses: actions/upload-artifact@v2
210113
with:
211114
name: dist
212-
path: dist/
115+
path: wheelhouse/*.whl
213116

214117
publish-docs:
215118
needs: validate-release-request

.github/workflows/test-wheels.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ jobs:
5959
with:
6060
python-version: ${{ matrix.python-version }}
6161

62-
- name: Configure PostgreSQL Environment
63-
if: matrix.os == 'windows-latest'
64-
run: |
65-
echo PGINSTALLATION="${PGBIN}" >> "${GITHUB_ENV}"
66-
6762
- name: Install Python Deps
6863
if: steps.release.outputs.version == 0
6964
run: |

asyncpg/cluster.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class Cluster:
5353
def __init__(self, data_dir, *, pg_config_path=None):
5454
self._data_dir = data_dir
5555
self._pg_config_path = pg_config_path
56-
self._pg_bin_dir = os.environ.get('PGINSTALLATION')
56+
self._pg_bin_dir = (
57+
os.environ.get('PGINSTALLATION')
58+
or os.environ.get('PGBIN')
59+
)
5760
self._pg_ctl = None
5861
self._daemon_pid = None
5962
self._daemon_process = None
@@ -518,7 +521,10 @@ def _run_pg_config(self, pg_config_path):
518521

519522
def _find_pg_config(self, pg_config_path):
520523
if pg_config_path is None:
521-
pg_install = os.environ.get('PGINSTALLATION')
524+
pg_install = (
525+
os.environ.get('PGINSTALLATION')
526+
or os.environ.get('PGBIN')
527+
)
522528
if pg_install:
523529
pg_config_path = platform_exe(
524530
os.path.join(pg_install, 'pg_config'))

0 commit comments

Comments
 (0)