Skip to content

Commit ef2b7cd

Browse files
committed
Fix the CI release system
setup.py rework has caused breakage in the wheels department. Fix that and a few other shortcomings identified in the process. Drop setuptools_scm, as it doesn't play nice with shallow clones made by Travis. Use git directly instead.
1 parent 7db9e4f commit ef2b7cd

11 files changed

+101
-83
lines changed

.ci/build-manylinux-wheels.sh

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@ set -e -x
55
# Compile wheels
66
PYTHON="/opt/python/${PYTHON_VERSION}/bin/python"
77
PIP="/opt/python/${PYTHON_VERSION}/bin/pip"
8-
${PIP} install --upgrade pip wheel
9-
${PIP} install --upgrade setuptools
10-
${PIP} install -r /io/.ci/requirements.txt
11-
make -C /io/ PYTHON="${PYTHON}"
12-
${PIP} wheel /io/ -w /io/dist/
8+
${PIP} install --upgrade setuptools pip wheel
9+
cd /io
10+
make clean
11+
${PYTHON} setup.py bdist_wheel
1312

1413
# Bundle external shared libraries into the wheels.
1514
for whl in /io/dist/*.whl; do
1615
auditwheel repair $whl -w /io/dist/
1716
rm /io/dist/*-linux_*.whl
1817
done
1918

19+
${PIP} install ${PYMODULE}[test] -f "file:///io/dist"
20+
2021
# Grab docker host, where Postgres should be running.
2122
export PGHOST=$(ip route | awk '/default/ { print $3 }' | uniq)
2223
export PGUSER="postgres"
2324

24-
PYTHON="/opt/python/${PYTHON_VERSION}/bin/python"
25-
PIP="/opt/python/${PYTHON_VERSION}/bin/pip"
26-
${PIP} install ${PYMODULE} --no-index -f file:///io/dist
2725
rm -rf /io/tests/__pycache__
28-
make -C /io/ PYTHON="${PYTHON}" testinstalled
26+
make -C /io PYTHON="${PYTHON}" testinstalled
2927
rm -rf /io/tests/__pycache__

.ci/travis-build-docs.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ if [[ "${BUILD}" != *docs* ]]; then
77
exit 0
88
fi
99

10-
pip install -U .[dev]
10+
pip install -U -e .[docs]
1111
make htmldocs SPHINXOPTS="-q -W -j4"

.ci/travis-build-wheels.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ if [ "${PACKAGE_VERSION}" == "${PYPI_VERSION}" ]; then
2424
fi
2525

2626

27-
pushd $(dirname $0) > /dev/null
28-
_root=$(dirname $(pwd -P))
29-
popd > /dev/null
27+
_root="${TRAVIS_BUILD_DIR}"
3028

3129

3230
_upload_wheels() {
@@ -35,6 +33,9 @@ _upload_wheels() {
3533
}
3634

3735

36+
pip install -U -r ".ci/requirements-publish.txt"
37+
38+
3839
if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
3940
for pyver in ${RELEASE_PYTHON_VERSIONS}; do
4041
ML_PYTHON_VERSION=$(python3 -c \
@@ -49,6 +50,7 @@ if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
4950
-v "${_root}":/io \
5051
-e "PYMODULE=${PYMODULE}" \
5152
-e "PYTHON_VERSION=${ML_PYTHON_VERSION}" \
53+
-e "ASYNCPG_VERSION=${PACKAGE_VERSION}" \
5254
"${ML_IMAGE}" /io/.ci/build-manylinux-wheels.sh
5355

5456
_upload_wheels
@@ -58,13 +60,11 @@ if [ "${TRAVIS_OS_NAME}" == "linux" ]; then
5860
elif [ "${TRAVIS_OS_NAME}" == "osx" ]; then
5961
export PGINSTALLATION="/usr/local/opt/postgresql@${PGVERSION}/bin"
6062

61-
make clean && make -C "${_root}"
62-
pip wheel "${_root}" -w "${_root}/dist/"
63+
make clean
64+
python setup.py bdist_wheel
6365

64-
pip install ${PYMODULE} --no-index -f "file:///${_root}/dist"
65-
pushd / >/dev/null
66-
make -C "${_root}" testinstalled
67-
popd >/dev/null
66+
pip install ${PYMODULE}[test] -f "file:///${_root}/dist"
67+
make -C "${_root}" ASYNCPG_VERSION="${PACKAGE_VERSION}" testinstalled
6868

6969
_upload_wheels
7070

.ci/travis-install.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ if [ "${TRAVIS_OS_NAME}" == "osx" ]; then
99
fi
1010

1111
pip install --upgrade setuptools pip wheel
12-
pip install --upgrade -e .[dev]
12+
pip download --dest=/tmp/deps .[test]
13+
pip install -U --no-index --find-links=/tmp/deps /tmp/deps/*

.ci/travis-release.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
set -e -x
44

55
if [ -z "${TRAVIS_TAG}" ]; then
6-
# Not a release
6+
# Not a tagged commit.
77
exit 0
88
fi
99

10-
pip install -U ".ci/requirements-publish.txt"
10+
pip install -U -r ".ci/requirements-publish.txt"
1111

1212
PACKAGE_VERSION=$(python ".ci/package-version.py")
1313
PYPI_VERSION=$(python ".ci/pypi-check.py" "${PYMODULE}")

.github/release_log.py

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
#
13
# Copyright (C) 2016-present the asyncpg authors and contributors
24
# <see AUTHORS file>
35
#

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
PYTHON ?= python
5+
ROOT = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
56

67

78
all: compile
@@ -30,13 +31,14 @@ test:
3031

3132

3233
testinstalled:
33-
$(PYTHON) tests/__init__.py
34-
USE_UVLOOP=1 $(PYTHON) tests/__init__.py
34+
cd /tmp && $(PYTHON) $(ROOT)/tests/__init__.py
35+
cd /tmp && USE_UVLOOP=1 $(PYTHON) $(ROOT)/tests/__init__.py
3536

3637

3738
quicktest:
3839
$(PYTHON) setup.py test
3940

4041

41-
htmldocs: compile
42+
htmldocs:
43+
$(PYTHON) setup.py build_ext --inplace
4244
$(MAKE) -C docs html

asyncpg/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@
2929
#
3030
# Source and wheel distributions built from development
3131
# snapshots will automatically include the git revision
32-
# in __version__, for example: '0.16.0.dev22+ge06ad03'
32+
# in __version__, for example: '0.16.0.dev0+ge06ad03'
3333

3434
__version__ = '0.16.0.dev0'

setup.py

+59-56
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pathlib
1616
import platform
1717
import re
18+
import subprocess
1819

1920
# We use vanilla build_ext, to avoid importing Cython via
2021
# the setuptools version.
@@ -28,18 +29,27 @@
2829

2930
CYTHON_DEPENDENCY = 'Cython==0.28.3'
3031

32+
# Minimal dependencies required to test asyncpg.
33+
TEST_DEPENDENCIES = [
34+
'flake8~=3.5.0',
35+
'uvloop>=0.8.0;platform_system!="Windows"',
36+
]
37+
38+
# Dependencies required to build documentation.
39+
DOC_DEPENDENCIES = [
40+
'Sphinx~=1.7.3',
41+
'sphinxcontrib-asyncio~=0.2.0',
42+
'sphinx_rtd_theme~=0.2.4',
43+
]
44+
3145
EXTRA_DEPENDENCIES = {
46+
'docs': DOC_DEPENDENCIES,
47+
'test': TEST_DEPENDENCIES,
3248
# Dependencies required to develop asyncpg.
3349
'dev': [
3450
CYTHON_DEPENDENCY,
35-
'flake8~=3.5.0',
36-
'pytest~=3.0.7',
37-
'uvloop>=0.8.0;platform_system!="Windows"',
38-
# Docs
39-
'Sphinx~=1.7.3',
40-
'sphinxcontrib-asyncio~=0.2.0',
41-
'sphinx_rtd_theme~=0.2.4',
42-
]
51+
'pytest>=3.6.0',
52+
] + DOC_DEPENDENCIES + TEST_DEPENDENCIES
4353
}
4454

4555

@@ -50,6 +60,45 @@
5060
CFLAGS.extend(['-fsigned-char', '-Wall', '-Wsign-compare', '-Wconversion'])
5161

5262

63+
_ROOT = pathlib.Path(__file__).parent
64+
65+
66+
with open(str(_ROOT / 'README.rst')) as f:
67+
readme = f.read()
68+
69+
70+
with open(str(_ROOT / 'asyncpg' / '__init__.py')) as f:
71+
for line in f:
72+
if line.startswith('__version__ ='):
73+
_, _, version = line.partition('=')
74+
VERSION = version.strip(" \n'\"")
75+
break
76+
else:
77+
raise RuntimeError(
78+
'unable to read the version from asyncpg/__init__.py')
79+
80+
81+
if (_ROOT / '.git').is_dir() and 'dev' in VERSION:
82+
# This is a git checkout, use git to
83+
# generate a precise version.
84+
def git_commitish():
85+
env = {}
86+
v = os.environ.get('PATH')
87+
if v is not None:
88+
env['PATH'] = v
89+
90+
git = subprocess.run(['git', 'rev-parse', 'HEAD'], env=env, cwd=_ROOT,
91+
stdout=subprocess.PIPE)
92+
if git.returncode == 0:
93+
commitish = git.stdout.strip().decode('ascii')
94+
else:
95+
commitish = 'unknown'
96+
97+
return commitish
98+
99+
VERSION += '+' + git_commitish()[:7]
100+
101+
53102
class VersionMixin:
54103

55104
def _fix_version(self, filename):
@@ -183,55 +232,10 @@ def finalize_options(self):
183232
super(build_ext, self).finalize_options()
184233

185234

186-
_ROOT = pathlib.Path(__file__).parent
187-
188-
189-
with open(str(_ROOT / 'README.rst')) as f:
190-
readme = f.read()
191-
192-
193-
with open(str(_ROOT / 'asyncpg' / '__init__.py')) as f:
194-
for line in f:
195-
if line.startswith('__version__ ='):
196-
_, _, version = line.partition('=')
197-
VERSION = version.strip(" \n'\"")
198-
break
199-
else:
200-
raise RuntimeError(
201-
'unable to read the version from asyncpg/__init__.py')
202-
203-
204-
extra_setup_kwargs = {}
205235
setup_requires = []
206236

207-
if (_ROOT / '.git').is_dir():
208-
# This is a git checkout, use setuptools_scm to
209-
# generage a precise version.
210-
def version_scheme(v):
211-
from setuptools_scm import version
212-
213-
if v.exact:
214-
fv = v.format_with("{tag}")
215-
if fv != VERSION:
216-
raise RuntimeError(
217-
'asyncpg.__version__ does not match the git tag')
218-
else:
219-
fv = v.format_next_version(
220-
version.guess_next_simple_semver,
221-
retain=version.SEMVER_MINOR)
222-
223-
if not fv.startswith(VERSION[:-1]):
224-
raise RuntimeError(
225-
'asyncpg.__version__ does not match the git tag')
226-
227-
return fv
228-
229-
setup_requires.append('setuptools_scm')
230-
extra_setup_kwargs['use_scm_version'] = {
231-
'version_scheme': version_scheme
232-
}
233-
234-
if not (_ROOT / 'asyncpg' / 'protocol' / 'protocol.c').exists():
237+
if (not (_ROOT / 'asyncpg' / 'protocol' / 'protocol.c').exists() or
238+
'--cython-always' in sys.argv):
235239
# No Cython output, require Cython to build.
236240
setup_requires.append(CYTHON_DEPENDENCY)
237241

@@ -273,5 +277,4 @@ def version_scheme(v):
273277
test_suite='tests.suite',
274278
extras_require=EXTRA_DEPENDENCIES,
275279
setup_requires=setup_requires,
276-
**extra_setup_kwargs
277280
)

tests/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
66

77

8+
import pathlib
89
import sys
910
import unittest
1011

1112

1213
def suite():
1314
test_loader = unittest.TestLoader()
14-
test_suite = test_loader.discover('.', pattern='test_*.py')
15+
test_suite = test_loader.discover(str(pathlib.Path(__file__).parent),
16+
pattern='test_*.py')
1517
return test_suite
1618

1719

tests/test__environment.py

+10
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ async def test_environment_server_version(self):
2727
'Expecting PostgreSQL version {pgver}, got {maj}.{min}.'.format(
2828
pgver=pgver, maj=srv_ver.major, min=srv_ver.minor)
2929
)
30+
31+
@unittest.skipIf(not os.environ.get('ASYNCPG_VERSION'),
32+
"environ[ASYNCPG_VERSION] is not set")
33+
async def test_environment_asyncpg_version(self):
34+
apgver = os.environ.get('ASYNCPG_VERSION')
35+
self.assertEqual(
36+
asyncpg.__version__, apgver,
37+
'Expecting asyncpg version {}, got {}.'.format(
38+
apgver, asyncpg.__version__)
39+
)

0 commit comments

Comments
 (0)