Skip to content

Commit 4e97acc

Browse files
author
Jesse De Loore
committed
Merge branch 'target_session_attr' of github.com:JesseDeLoore/asyncpg into target_session_attr
2 parents 3bc8322 + 980004c commit 4e97acc

17 files changed

+129
-90
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
ignore = E402,E731,W503,W504,E252
3-
exclude = .git,__pycache__,build,dist,.eggs,.github,.local
3+
exclude = .git,__pycache__,build,dist,.eggs,.github,.local,.venv

.github/workflows/install-postgres.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then
2727
apt-get install -y --no-install-recommends \
2828
"postgresql-${PGVERSION}" \
2929
"postgresql-contrib-${PGVERSION}"
30+
elif [ "${ID}" = "almalinux" ]; then
31+
yum install -y \
32+
"postgresql-server" \
33+
"postgresql-devel" \
34+
"postgresql-contrib"
3035
elif [ "${ID}" = "centos" ]; then
31-
el="EL-${VERSION_ID}-$(arch)"
36+
el="EL-${VERSION_ID%.*}-$(arch)"
3237
baseurl="https://download.postgresql.org/pub/repos/yum/reporpms"
3338
yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm"
34-
if [ ${VERSION_ID} -ge 8 ]; then
39+
if [ ${VERSION_ID%.*} -ge 8 ]; then
3540
dnf -qy module disable postgresql
3641
fi
3742
yum install -y \

.github/workflows/release.yml

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
mkdir -p dist/
3838
echo "${VERSION}" > dist/VERSION
3939
40-
- uses: actions/upload-artifact@v2
40+
- uses: actions/upload-artifact@v3
4141
with:
4242
name: dist
4343
path: dist/
@@ -50,37 +50,56 @@ jobs:
5050
PIP_DISABLE_PIP_VERSION_CHECK: 1
5151

5252
steps:
53-
- uses: actions/checkout@v2
53+
- uses: actions/checkout@v3
5454
with:
5555
fetch-depth: 50
5656
submodules: true
5757

5858
- name: Set up Python
59-
uses: actions/setup-python@v2
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: "3.x"
6062

6163
- name: Build source distribution
6264
run: |
6365
pip install -U setuptools wheel pip
6466
python setup.py sdist
6567
66-
- uses: actions/upload-artifact@v2
68+
- uses: actions/upload-artifact@v3
6769
with:
6870
name: dist
6971
path: dist/*.tar.*
7072

71-
build-wheels:
73+
build-wheels-matrix:
7274
needs: validate-release-request
75+
runs-on: ubuntu-latest
76+
outputs:
77+
include: ${{ steps.set-matrix.outputs.include }}
78+
steps:
79+
- uses: actions/checkout@v3
80+
- uses: actions/setup-python@v4
81+
with:
82+
python-version: "3.x"
83+
- run: pip install cibuildwheel==2.10.2
84+
- id: set-matrix
85+
run: |
86+
MATRIX_INCLUDE=$(
87+
{
88+
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64 | grep cp | jq -Rc '{"only": inputs, "os": "ubuntu-latest"}' \
89+
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64,arm64 | grep cp | jq -Rc '{"only": inputs, "os": "macos-latest"}' \
90+
&& cibuildwheel --print-build-identifiers --platform windows --arch x86,AMD64 | grep cp | jq -Rc '{"only": inputs, "os": "windows-latest"}'
91+
} | jq -sc
92+
)
93+
echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
94+
95+
build-wheels:
96+
needs: build-wheels-matrix
7397
runs-on: ${{ matrix.os }}
98+
name: Build ${{ matrix.only }}
99+
74100
strategy:
75101
matrix:
76-
os: [ubuntu-latest, macos-latest, windows-latest]
77-
cibw_python: ["cp36-*", "cp37-*", "cp38-*", "cp39-*", "cp310-*"]
78-
cibw_arch: ["auto64", "auto32"]
79-
exclude:
80-
- os: macos-latest
81-
cibw_arch: "auto32"
82-
- os: ubuntu-latest
83-
cibw_arch: "auto32"
102+
include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }}
84103

85104
defaults:
86105
run:
@@ -90,48 +109,54 @@ jobs:
90109
PIP_DISABLE_PIP_VERSION_CHECK: 1
91110

92111
steps:
93-
- uses: actions/checkout@v2
112+
- uses: actions/checkout@v3
94113
with:
95114
fetch-depth: 50
96115
submodules: true
97116

98-
- uses: pypa/[email protected]
117+
- name: Set up QEMU
118+
if: runner.os == 'Linux'
119+
uses: docker/setup-qemu-action@v2
120+
121+
- uses: pypa/[email protected]
122+
with:
123+
only: ${{ matrix.only }}
99124
env:
100125
CIBW_BUILD_VERBOSITY: 1
101-
CIBW_BUILD: ${{ matrix.cibw_python }}
102-
CIBW_ARCHS: ${{ matrix.cibw_arch }}
126+
CIBW_MANYLINUX_X86_64_IMAGE: manylinux_2_28
127+
CIBW_MANYLINUX_AARCH64_IMAGE: manylinux_2_28
103128

104-
- uses: actions/upload-artifact@v2
129+
- uses: actions/upload-artifact@v3
105130
with:
106131
name: dist
107132
path: wheelhouse/*.whl
108133

109134
publish-docs:
110-
needs: validate-release-request
135+
needs: [build-sdist, build-wheels]
111136
runs-on: ubuntu-latest
112137

113138
env:
114139
PIP_DISABLE_PIP_VERSION_CHECK: 1
115140

116141
steps:
117142
- name: Checkout source
118-
uses: actions/checkout@v2
143+
uses: actions/checkout@v3
119144
with:
120145
fetch-depth: 5
121146
submodules: true
122147

123148
- name: Set up Python
124-
uses: actions/setup-python@v2
149+
uses: actions/setup-python@v4
125150
with:
126-
python-version: 3.8
151+
python-version: "3.x"
127152

128153
- name: Build docs
129154
run: |
130155
pip install -e .[dev]
131156
make htmldocs
132157
133158
- name: Checkout gh-pages
134-
uses: actions/checkout@v2
159+
uses: actions/checkout@v3
135160
with:
136161
fetch-depth: 5
137162
ref: gh-pages
@@ -157,12 +182,12 @@ jobs:
157182
runs-on: ubuntu-latest
158183

159184
steps:
160-
- uses: actions/checkout@v2
185+
- uses: actions/checkout@v3
161186
with:
162187
fetch-depth: 5
163188
submodules: false
164189

165-
- uses: actions/download-artifact@v2
190+
- uses: actions/download-artifact@v3
166191
with:
167192
name: dist
168193
path: dist/
@@ -171,7 +196,7 @@ jobs:
171196
id: relver
172197
run: |
173198
set -e
174-
echo ::set-output name=version::$(cat dist/VERSION)
199+
echo "version=$(cat dist/VERSION)" >> $GITHUB_OUTPUT
175200
rm dist/VERSION
176201
177202
- name: Merge and tag the PR
@@ -197,7 +222,7 @@ jobs:
197222
ls -al dist/
198223
199224
- name: Upload to PyPI
200-
uses: pypa/gh-action-pypi-publish@master
225+
uses: pypa/gh-action-pypi-publish@release/v1
201226
with:
202227
user: __token__
203228
password: ${{ secrets.PYPI_TOKEN }}

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ of PostgreSQL server binary protocol for use with Python's ``asyncio``
1313
framework. You can read more about asyncpg in an introductory
1414
`blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_.
1515

16-
asyncpg requires Python 3.6 or later and is supported for PostgreSQL
17-
versions 9.5 to 14. Older PostgreSQL versions or other databases implementing
16+
asyncpg requires Python 3.7 or later and is supported for PostgreSQL
17+
versions 9.5 to 15. Older PostgreSQL versions or other databases implementing
1818
the PostgreSQL protocol *may* work, but are not being actively tested.
1919

2020

asyncpg/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# supported platforms, publish the packages on PyPI, merge the PR
1111
# to the target branch, create a Git tag pointing to the commit.
1212

13-
__version__ = '0.26.0'
13+
__version__ = '0.28.0.dev0'

asyncpg/compat.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import asyncio
99
import pathlib
1010
import platform
11-
import sys
1211

1312

14-
PY_37 = sys.version_info >= (3, 7)
1513
SYSTEM = platform.uname().system
1614

1715

@@ -36,14 +34,6 @@ def get_pg_home_directory() -> pathlib.Path:
3634
return pathlib.Path.home()
3735

3836

39-
if PY_37:
40-
def current_asyncio_task(loop):
41-
return asyncio.current_task(loop)
42-
else:
43-
def current_asyncio_task(loop):
44-
return asyncio.Task.current_task(loop)
45-
46-
4737
async def wait_closed(stream):
4838
# Not all asyncio versions have StreamWriter.wait_closed().
4939
if hasattr(stream, 'wait_closed'):

asyncpg/connect_utils.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@ def _parse_hostlist(hostlist, port, *, unquote=False):
239239

240240

241241
def _parse_tls_version(tls_version):
242-
if not hasattr(ssl_module, 'TLSVersion'):
243-
raise ValueError(
244-
"TLSVersion is not supported in this version of Python"
245-
)
246242
if tls_version.startswith('SSL'):
247243
raise ValueError(
248244
f"Unsupported TLS version: {tls_version}"
@@ -576,11 +572,7 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
576572
ssl_min_protocol_version
577573
)
578574
else:
579-
try:
580-
ssl.minimum_version = _parse_tls_version('TLSv1.2')
581-
except ValueError:
582-
# Python 3.6 does not have ssl.TLSVersion
583-
pass
575+
ssl.minimum_version = _parse_tls_version('TLSv1.2')
584576

585577
if ssl_max_protocol_version is None:
586578
ssl_max_protocol_version = os.getenv('PGSSLMAXPROTOCOLVERSION')

asyncpg/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import warnings
2121
import weakref
2222

23-
from . import compat
2423
from . import connect_utils
2524
from . import cursor
2625
from . import exceptions
@@ -1418,6 +1417,7 @@ def _mark_stmts_as_closed(self):
14181417
def _maybe_gc_stmt(self, stmt):
14191418
if (
14201419
stmt.refs == 0
1420+
and stmt.name
14211421
and not self._stmt_cache.has(
14221422
(stmt.query, stmt.record_class, stmt.ignore_custom_codec)
14231423
)
@@ -1469,7 +1469,7 @@ async def _cancel(self, waiter):
14691469
waiter.set_exception(ex)
14701470
finally:
14711471
self._cancellations.discard(
1472-
compat.current_asyncio_task(self._loop))
1472+
asyncio.current_task(self._loop))
14731473
if not waiter.done():
14741474
waiter.set_result(None)
14751475

asyncpg/pool.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ def __new__(mcls, name, bases, dct, *, wrap=False):
4343

4444
return super().__new__(mcls, name, bases, dct)
4545

46-
def __init__(cls, name, bases, dct, *, wrap=False):
47-
# Needed for Python 3.5 to handle `wrap` class keyword argument.
48-
super().__init__(name, bases, dct)
49-
5046
@staticmethod
5147
def _wrap_connection_method(meth_name):
5248
def call_con_method(self, *args, **kwargs):
@@ -450,6 +446,13 @@ async def _initialize(self):
450446

451447
await asyncio.gather(*connect_tasks)
452448

449+
def is_closing(self):
450+
"""Return ``True`` if the pool is closing or is closed.
451+
452+
.. versionadded:: 0.28.0
453+
"""
454+
return self._closed or self._closing
455+
453456
def get_size(self):
454457
"""Return the current number of connections in this pool.
455458

asyncpg/protocol/record/recordobj.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,31 @@ record_subscript(ApgRecordObject* o, PyObject* item)
451451
}
452452

453453

454+
static const char *
455+
get_typename(PyTypeObject *type)
456+
{
457+
assert(type->tp_name != NULL);
458+
const char *s = strrchr(type->tp_name, '.');
459+
if (s == NULL) {
460+
s = type->tp_name;
461+
}
462+
else {
463+
s++;
464+
}
465+
return s;
466+
}
467+
468+
454469
static PyObject *
455470
record_repr(ApgRecordObject *v)
456471
{
457472
Py_ssize_t i, n;
458-
PyObject *keys_iter;
473+
PyObject *keys_iter, *type_prefix;
459474
_PyUnicodeWriter writer;
460475

461476
n = Py_SIZE(v);
462477
if (n == 0) {
463-
return PyUnicode_FromString("<Record>");
478+
return PyUnicode_FromFormat("<%s>", get_typename(Py_TYPE(v)));
464479
}
465480

466481
keys_iter = PyObject_GetIter(v->desc->keys);
@@ -471,16 +486,22 @@ record_repr(ApgRecordObject *v)
471486
i = Py_ReprEnter((PyObject *)v);
472487
if (i != 0) {
473488
Py_DECREF(keys_iter);
474-
return i > 0 ? PyUnicode_FromString("<Record ...>") : NULL;
489+
if (i > 0) {
490+
return PyUnicode_FromFormat("<%s ...>", get_typename(Py_TYPE(v)));
491+
}
492+
return NULL;
475493
}
476494

477495
_PyUnicodeWriter_Init(&writer);
478496
writer.overallocate = 1;
479497
writer.min_length = 12; /* <Record a=1> */
480498

481-
if (_PyUnicodeWriter_WriteASCIIString(&writer, "<Record ", 8) < 0) {
499+
type_prefix = PyUnicode_FromFormat("<%s ", get_typename(Py_TYPE(v)));
500+
if (_PyUnicodeWriter_WriteStr(&writer, type_prefix) < 0) {
501+
Py_DECREF(type_prefix);
482502
goto error;
483503
}
504+
Py_DECREF(type_prefix);
484505

485506
for (i = 0; i < n; ++i) {
486507
PyObject *key;

0 commit comments

Comments
 (0)