Skip to content

Commit

Permalink
Merge branch 'main' into readme
Browse files Browse the repository at this point in the history
Signed-off-by: Callan Gray <[email protected]>
  • Loading branch information
calgray committed Jan 1, 2025
2 parents c24ca5c + 2bc375d commit 809c820
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit_autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: browniebroke/pre-commit-autoupdate-action@main
- uses: peter-evans/create-pull-request@v6
- uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![PyPI version shields.io](https://img.shields.io/pypi/v/athreading.svg)](https://pypi.python.org/pypi/athreading)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/athreading.svg)](https://pypi.python.org/pypi/athreading)

`athreading` is a Python library that allows you to run synchronous I/O functions asynchronously using `asyncio`. It provides decorators to adapt synchronous functions and generators, enabling them to operate without blocking the event loop.
`athreading` is a Python library that allows you to run synchronous I/O functions asynchronously using `asyncio` via background threads. It provides decorators to adapt synchronous functions and generators, enabling them to operate without blocking the event loop.

## Features

Expand Down
416 changes: 223 additions & 193 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "athreading"
version = "0.1.2"
description = ""
description = "Asynchronous threading package for Python"
readme = "README.md"
authors = ["Callan Gray <[email protected]>"]
license = "BSD-3-Clause"
packages = [{ include = "athreading", from = "src" }]
Expand All @@ -15,19 +16,20 @@ python = "^3.9"

[tool.poetry.group.test.dependencies]
pytest = ">=7,<9"
pytest-cov = "^4.0.0"
pytest-cov = ">=4,<7"
pytest-mypy = "^0.10.0"
pytest-mock = "^3.7.0"
pytest-asyncio = "^0.20.3"
pytest-benchmark = "^4.0.0"
pytest-mock = "^3.14.0"
pytest-asyncio = ">=0.20.3,<0.26.0"
pytest-benchmark = "^5.1.0"
isort = "^5.10.1"
pre-commit = "^3.0.4"
pre-commit = ">=3.0.4,<5.0.0"
black = ">=23.1,<25.0"
flake8 = ">=6,<8"
flake8-docstrings = "^1.6.0"
flake8-pyproject = "^1.2.2"
aiostream = ">=0.4.5,<0.6.0"
aiostream = ">=0.4.5,<0.7.0"
threaded = "^4.2.0"
typing_extensions = { python = "3.13", version = ">4.12.0" }

[tool.mypy]
disallow_any_explicit = true
Expand Down
31 changes: 31 additions & 0 deletions tests/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from contextlib import AbstractAsyncContextManager, AbstractContextManager
from typing import TypeVar

T = TypeVar("T")


class nullcontext(AbstractContextManager[T], AbstractAsyncContextManager[T]):
"""Context manager that does no additional processing.
Used as a stand-in for a normal context manager, when a particular
block of code is only sometimes used with a normal context manager:
cm = optional_cm if condition else nullcontext()
with cm:
# Perform operation, using optional_cm if condition is True
"""

def __init__(self, enter_result=None):
self.enter_result = enter_result

def __enter__(self):
return self.enter_result

def __exit__(self, *excinfo):
pass

async def __aenter__(self):
return self.enter_result

async def __aexit__(self, *excinfo):
pass
8 changes: 7 additions & 1 deletion tests/unit/test_send.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import sys
import time
from collections.abc import AsyncGenerator, Generator
from typing import Optional
Expand All @@ -7,6 +8,11 @@

import athreading

if sys.version_info[:2] > (3, 9):
from contextlib import nullcontext
else:
from tests.compat import nullcontext


def doubler(delay: float) -> Generator[int, Optional[int], None]:
"""
Expand Down Expand Up @@ -41,7 +47,7 @@ async def adoubler(delay: float) -> AsyncGenerator[int, Optional[int]]:
@pytest.mark.parametrize(
"streamcontext",
[
lambda delay: adoubler(delay),
lambda delay: nullcontext(adoubler(delay)),
lambda delay: athreading.generate(doubler)(delay),
],
ids=["adoubler", "generate"],
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/test_throw.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import time
from collections.abc import AsyncGenerator, Generator
from typing import Optional
Expand All @@ -6,6 +7,11 @@

import athreading

if sys.version_info[:2] > (3, 9):
from contextlib import nullcontext
else:
from tests.compat import nullcontext


def generate_infinite(delay: float) -> Generator[int, Optional[int], None]:
while True:
Expand All @@ -30,7 +36,7 @@ async def agenerate_infinite(delay: float) -> AsyncGenerator[int, Optional[int]]
@pytest.mark.parametrize(
"streamcontext",
[
lambda delay: agenerate_infinite(delay),
lambda delay: nullcontext(agenerate_infinite(delay)),
lambda delay: athreading.generate(generate_infinite)(delay),
],
ids=["control", "generate"],
Expand All @@ -52,7 +58,7 @@ async def test_throw_immediate(streamcontext, worker_delay, main_delay):
@pytest.mark.parametrize(
"streamcontext",
[
lambda delay: agenerate_infinite(delay),
lambda delay: nullcontext(agenerate_infinite(delay)),
lambda delay: athreading.generate(generate_infinite)(delay),
],
ids=["control", "generate"],
Expand Down

0 comments on commit 809c820

Please sign in to comment.