Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for python 3.13 #2

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
os: [windows-latest, ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}
Expand Down
713 changes: 713 additions & 0 deletions py3.13.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: MIT License",
]

Expand Down
30 changes: 27 additions & 3 deletions src/calendar_queue/calendar_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
from heapq import heappop as heap_pop
from heapq import heappush as heap_push
import math
import sys
from time import time
from typing import Callable, Generic, Optional, TypeVar, Union

if sys.version_info >= (3, 13):
from asyncio import QueueShutDown
else:
QueueShutDown = ValueError


CalendarEvent = TypeVar("CalendarEvent")


Expand Down Expand Up @@ -77,9 +84,14 @@ async def get(self) -> tuple[float, CalendarEvent]:

If queue is empty, wait until an item is available.

Raises:
QueueShutDown: (Only in python >= 3.13) if the queue has been
shut down and is empty, or if the queue has been shut down
immediately.

Returns:
(Tuple[float, CalendarEvent]): Tuple containing the scheduled
timestamp and the even
timestamp and the event.
"""

# we should await if the queue is empty or if the timer
Expand All @@ -89,6 +101,9 @@ async def get(self) -> tuple[float, CalendarEvent]:
and self._getter_timer.when() > self._get_loop().time()
):

if getattr(self, "_is_shutdown", False) and self.empty():
raise QueueShutDown

getter = self._get_loop().create_future()
self._getters.append(getter)
try:
Expand Down Expand Up @@ -121,9 +136,15 @@ async def put(self, item: tuple[Union[float, int], CalendarEvent]) -> None:
slot is available before adding item.

Args:
item (tuple[Union[float, int], CalendarEvent]): Item to put in the queue
item (tuple[Union[float, int], CalendarEvent]): Item to put in the queue.

Raises:
QueueShutDown: (Only in python >= 3.13) if the queue has been
shut down.
"""
while self.full():
if getattr(self, "_is_shutdown", False):
raise QueueShutDown
putter = self._get_loop().create_future()
self._putters.append(putter)
try:
Expand Down Expand Up @@ -153,8 +174,11 @@ def put_nowait(self, item: tuple[Union[float, int], CalendarEvent]):
item (tuple[Union[float, int], CalendarEvent]): Item to put in the queue

Raises:
QueueFull: when queue is full
QueueFull: when queue is full.
QueueShutDown: (Only in python >= 3.13) if the queue has been shut down.
"""
if getattr(self, "_is_shutdown", False):
raise QueueShutDown
if self.full():
raise QueueFull
self._put(item)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_calendar_queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import math
import sys
from datetime import datetime, timedelta
from time import time

Expand All @@ -15,6 +16,29 @@ def test_init():
assert CalendarQueue()


@pytest.mark.asyncio
@pytest.mark.skipif(
sys.version_info <= (3, 13),
reason="Queue shutdown is supported only from python 3.13 on",
)
async def test_queue_shutdown():
"""Test for python >= 3.13 only. Check that QueueShutDown
is correctly raised when putting or getting after shutting down the queue
"""

from asyncio import QueueShutDown

cq = CalendarQueue()

cq.shutdown()

with pytest.raises(QueueShutDown):
await cq.get()

with pytest.raises(QueueShutDown):
await cq.put((time() + 10, "foo"))


@pytest.mark.asyncio
async def test_simple_put():
"""Test put by putting one element and checking that
Expand Down
2 changes: 1 addition & 1 deletion utils/update-lockfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
echo "Found $PDM_VERSION"
fi

SUPPORTED_PYTHON_VERSIONS=("3.10" "3.11" "3.12")
SUPPORTED_PYTHON_VERSIONS=("3.10" "3.11" "3.12" "3.13")

ERROR=0

Expand Down