Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Oct 9, 2023
2 parents 2621c92 + b2697ff commit d59071c
Show file tree
Hide file tree
Showing 37 changed files with 1,109 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
ignore = E402,E731,W503,W504,E252
exclude = .git,__pycache__,build,dist,.eggs,.github,.local,.venv
exclude = .git,__pycache__,build,dist,.eggs,.github,.local,.venv,.tox
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
PIP_DISABLE_PIP_VERSION_CHECK: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
Expand All @@ -76,11 +76,11 @@ jobs:
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- run: pip install cibuildwheel==2.13.1
- run: pip install cibuildwheel==2.16.2
- id: set-matrix
run: |
MATRIX_INCLUDE=$(
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
PIP_DISABLE_PIP_VERSION_CHECK: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
Expand All @@ -118,7 +118,7 @@ jobs:
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2

- uses: pypa/cibuildwheel@v2.13.1
- uses: pypa/cibuildwheel@fff9ec32ed25a9c576750c91e06b410ed0c15db7 # v2.16.2
with:
only: ${{ matrix.only }}
env:
Expand All @@ -138,7 +138,7 @@ jobs:

steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 5
submodules: true
Expand All @@ -154,7 +154,7 @@ jobs:
make htmldocs
- name: Checkout gh-pages
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 5
ref: gh-pages
Expand All @@ -180,7 +180,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 5
submodules: false
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ jobs:
# job.
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
loop: [asyncio, uvloop]
exclude:
# uvloop does not support windows
- loop: uvloop
os: windows-latest
# No 3.12 release yet
- loop: uvloop
python-version: "3.12"

runs-on: ${{ matrix.os }}

Expand All @@ -35,7 +38,7 @@ jobs:
PIP_DISABLE_PIP_VERSION_CHECK: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
Expand Down Expand Up @@ -76,15 +79,15 @@ jobs:
test-postgres:
strategy:
matrix:
postgres-version: ["9.5", "9.6", "10", "11", "12", "13", "14", "15"]
postgres-version: ["9.5", "9.6", "10", "11", "12", "13", "14", "15", "16"]

runs-on: ubuntu-latest

env:
PIP_DISABLE_PIP_VERSION_CHECK: 1

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 50
submodules: true
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ of PostgreSQL server binary protocol for use with Python's ``asyncio``
framework. You can read more about asyncpg in an introductory
`blog post <http://magic.io/blog/asyncpg-1m-rows-from-postgres-to-python/>`_.

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


Expand Down
87 changes: 87 additions & 0 deletions asyncpg/_asyncio_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Backports from Python/Lib/asyncio for older Pythons
#
# Copyright (c) 2001-2023 Python Software Foundation; All Rights Reserved
#
# SPDX-License-Identifier: PSF-2.0


import asyncio
import functools
import sys

if sys.version_info < (3, 11):
from async_timeout import timeout as timeout_ctx
else:
from asyncio import timeout as timeout_ctx


async def wait_for(fut, timeout):
"""Wait for the single Future or coroutine to complete, with timeout.
Coroutine will be wrapped in Task.
Returns result of the Future or coroutine. When a timeout occurs,
it cancels the task and raises TimeoutError. To avoid the task
cancellation, wrap it in shield().
If the wait is cancelled, the task is also cancelled.
If the task supresses the cancellation and returns a value instead,
that value is returned.
This function is a coroutine.
"""
# The special case for timeout <= 0 is for the following case:
#
# async def test_waitfor():
# func_started = False
#
# async def func():
# nonlocal func_started
# func_started = True
#
# try:
# await asyncio.wait_for(func(), 0)
# except asyncio.TimeoutError:
# assert not func_started
# else:
# assert False
#
# asyncio.run(test_waitfor())

if timeout is not None and timeout <= 0:
fut = asyncio.ensure_future(fut)

if fut.done():
return fut.result()

await _cancel_and_wait(fut)
try:
return fut.result()
except asyncio.CancelledError as exc:
raise TimeoutError from exc

async with timeout_ctx(timeout):
return await fut


async def _cancel_and_wait(fut):
"""Cancel the *fut* future or task and wait until it completes."""

loop = asyncio.get_running_loop()
waiter = loop.create_future()
cb = functools.partial(_release_waiter, waiter)
fut.add_done_callback(cb)

try:
fut.cancel()
# We cannot wait on *fut* directly to make
# sure _cancel_and_wait itself is reliably cancellable.
await waiter
finally:
fut.remove_done_callback(cb)


def _release_waiter(waiter, *args):
if not waiter.done():
waiter.set_result(None)
22 changes: 9 additions & 13 deletions asyncpg/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0


import asyncio
import pathlib
import platform
import typing
import sys


SYSTEM = platform.uname().system
Expand Down Expand Up @@ -49,17 +49,13 @@ async def wait_closed(stream):
pass


# Workaround for https://bugs.python.org/issue37658
async def wait_for(fut, timeout):
if timeout is None:
return await fut
if sys.version_info < (3, 12):
from ._asyncio_compat import wait_for as wait_for # noqa: F401
else:
from asyncio import wait_for as wait_for # noqa: F401

fut = asyncio.ensure_future(fut)

try:
return await asyncio.wait_for(fut, timeout)
except asyncio.CancelledError:
if fut.done():
return fut.result()
else:
raise
if sys.version_info < (3, 11):
from ._asyncio_compat import timeout_ctx as timeout # noqa: F401
else:
from asyncio import timeout as timeout # noqa: F401
Loading

0 comments on commit d59071c

Please sign in to comment.