Skip to content

Commit

Permalink
chore: Upgrade dependencies + enable on Python 3.12 and 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
tibordp committed Nov 25, 2024
1 parent 5cb534e commit 5c37143
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
toxenv: py310
- python-version: "3.11"
toxenv: py311
- python-version: "3.12"
toxenv: py312
- python-version: "3.13"
toxenv: py313
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.environment['python-version'] }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ exclude: '^(\.tox|ci/templates|\.bumpversion\.cfg)(/|$)'
# Note the order is intentional to avoid multiple passes of the hooks
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.263
rev: v0.8.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ RUN apt-get update -y \
python3.10-distutils \
python3.11 \
python3.11-distutils \
python3.12 \
python3.12-distutils \
python3-pip \
python3-apt \
redis-tools \
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.1"

services:
postgres:
image: postgres
Expand Down
19 changes: 11 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ requires = [
"setuptools_scm>=3.3.1",
]

[tool.ruff.per-file-ignores]
"ci/*" = ["S"]

[tool.ruff]
extend-exclude = ["static", "ci/templates"]
line-length = 140
src = ["src", "tests"]
target-version = "py38"

[tool.ruff.lint]
ignore = [
"RUF001", # ruff-specific rules ambiguous-unicode-character-string
"S608", # SQL injection - we specifically inject table name
Expand All @@ -20,7 +23,6 @@ ignore = [
"S308", # flake8-bandit suspicious-mark-safe-usage
"E501", # pycodestyle line-too-long
]
line-length = 140
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
Expand All @@ -42,20 +44,21 @@ select = [
"UP", # pyupgrade
"W", # pycodestyle warnings
]
src = ["src", "tests"]
target-version = "py37"

[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.per-file-ignores]
"ci/*" = ["S"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.isort]
[tool.ruff.lint.isort]
forced-separate = ["conftest"]
force-single-line = true

[tool.black]
line-length = 140
target-version = ["py37"]
target-version = ["py38"]

[tool.mypy]
ignore_missing_imports = true
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def read(*names, **kwargs):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Utilities",
],
Expand Down
2 changes: 1 addition & 1 deletion src/pyncette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .pyncette import Pyncette
from .pyncette import PyncetteContext

__all__ = ["Pyncette", "ExecutionMode", "FailureMode", "Context", "PyncetteContext"]
__all__ = ["Context", "ExecutionMode", "FailureMode", "Pyncette", "PyncetteContext"]
16 changes: 10 additions & 6 deletions src/pyncette/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ async def _update_item(self, task: Task, record: _TaskRecord) -> bool:
"partition_id": self._get_partition_id(task),
"task_id": task.canonical_name,
},
ConditionExpression=(Attr("version").not_exists() | Attr("version").eq(0))
if current_version == 0
else Attr("version").eq(current_version),
ConditionExpression=(
(Attr("version").not_exists() | Attr("version").eq(0))
if current_version == 0
else Attr("version").eq(current_version)
),
)
task._last_lease = None # type: ignore
else:
Expand All @@ -189,9 +191,11 @@ async def _update_item(self, task: Task, record: _TaskRecord) -> bool:
":ready_at": f"{ready_at.isoformat()}_{task.canonical_name}",
":version": current_version + 1,
},
ConditionExpression=(Attr("version").not_exists() | Attr("version").eq(0))
if current_version == 0
else Attr("version").eq(current_version),
ConditionExpression=(
(Attr("version").not_exists() | Attr("version").eq(0))
if current_version == 0
else Attr("version").eq(current_version)
),
)
record.version = current_version + 1
task._last_lease = record # type: ignore
Expand Down
6 changes: 2 additions & 4 deletions src/pyncette/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ class Context:

if TYPE_CHECKING:

def __getattr__(self, name: str) -> Any:
...
def __getattr__(self, name: str) -> Any: ...

def __setattr__(self, name: str, value: Any) -> Any:
...
def __setattr__(self, name: str, value: Any) -> Any: ...


class TaskFunc(Protocol):
Expand Down
7 changes: 3 additions & 4 deletions src/pyncette/pyncette.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from typing import AsyncIterator
from typing import Awaitable
from typing import Callable
from typing import Deque
from typing import Sequence

import coloredlogs
Expand Down Expand Up @@ -93,7 +92,7 @@ async def unschedule_task(self, task: Task, instance_name: str | None = None) ->
utc_now = _current_time()
await self._repository.unregister_task(utc_now, concrete_task)

async def _heartbeat(self, task: Task, context: Context, lease: Lease) -> None:
async def _heartbeat(self, task: Task, context: Context) -> None:
utc_now = _current_time()

# For best-effort tasks, there are no leases to be had
Expand All @@ -115,7 +114,7 @@ def _populate_context(self, task: Task, poll_response: PollResponse) -> Context:
context.scheduled_at = poll_response.scheduled_at.astimezone(tz)
context.args = copy.copy(task.extra_args)
context._lease = poll_response.lease
context.heartbeat = partial(self._heartbeat, task, context, poll_response.lease)
context.heartbeat = partial(self._heartbeat, task, context)

return context

Expand Down Expand Up @@ -156,7 +155,7 @@ async def _execute_task(self, task: Task, poll_response: PollResponse) -> None:
)

async def _get_active_tasks(self, utc_now: datetime.datetime, tasks: Sequence[Task]) -> AsyncIterator[tuple[Task, Lease | None]]:
queue: Deque[tuple[Task, ContinuationToken | None]] = collections.deque((task, None) for task in tasks)
queue: collections.deque[tuple[Task, ContinuationToken | None]] = collections.deque((task, None) for task in tasks)

while queue and not self._shutting_down.is_set():
task, continuation_token = queue.popleft()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_pyncette_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

@pytest.mark.integration
def test_signal_handling():
with subprocess.Popen(
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S603,S607
with subprocess.Popen( # noqa: S603
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S607
env={**os.environ, "LOG_LEVEL": "DEBUG"},
) as proc:
time.sleep(2)
Expand All @@ -22,8 +22,8 @@ def test_signal_handling():

@pytest.mark.integration
def test_signal_handling_uvloop():
with subprocess.Popen(
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S603,S607
with subprocess.Popen( # noqa: S603
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S607
env={**os.environ, "LOG_LEVEL": "DEBUG", "USE_UVLOOP": "1"},
) as proc:
time.sleep(2)
Expand All @@ -35,8 +35,8 @@ def test_signal_handling_uvloop():

@pytest.mark.integration
def test_signal_handling_force():
with subprocess.Popen(
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S603,S607
with subprocess.Popen( # noqa: S603
["coverage", "run", "-m", "tests.test_pyncette_process"], # noqa: S607
env={**os.environ, "LOG_LEVEL": "DEBUG"},
) as proc:
time.sleep(2)
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ envlist =
clean,
check,
docs,
{py38,py39,py310,py311},
{py38,py39,py310,py311,py312,py313},
integration,
report
ignore_basepython_conflict = true

[testenv]
basepython =
py37: {env:TOXPYTHON:python3.7}
py38: {env:TOXPYTHON:python3.8}
py39: {env:TOXPYTHON:python3.9}
py310: {env:TOXPYTHON:python3.10}
py311: {env:TOXPYTHON:python3.11}
py312: {env:TOXPYTHON:python3.12}
py313: {env:TOXPYTHON:python3.13}
{integration,docs}: {env:TOXPYTHON:python3}
{bootstrap,clean,check,report}: {env:TOXPYTHON:python3}
setenv =
Expand Down

0 comments on commit 5c37143

Please sign in to comment.