Skip to content

Commit

Permalink
docs: change theme
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Oct 27, 2024
1 parent ceb2cf5 commit b91acc7
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 527 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 4

[*.{js,ts,yaml,yml,html,json,css}]
indent_size = 2
19 changes: 6 additions & 13 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,9 @@ build:
os: ubuntu-22.04
tools:
python: "3.12"
jobs:
post_create_environment:
- pip install uv
- uv pip compile --extra docs pyproject.toml -o requirements.txt
post_install:
- pip install -e .

python:
install:
- requirements: requirements.txt

sphinx:
configuration: src/docs/conf.py
commands:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
- uv sync --group docs
- uv run -m sphinx -T -b html -d docs/_build/doctrees -D language=en src/docs $READTHEDOCS_OUTPUT/html
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SPHINXBUILD ?= uv run sphinx-build
SOURCEDIR = src/docs
BUILDDIR = build

Expand Down
35 changes: 0 additions & 35 deletions make.bat

This file was deleted.

38 changes: 25 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,48 @@ Repository = "https://github.com/phi-friday/async-wrapper"
[project.optional-dependencies]
uvloop = ["uvloop; platform_system != 'Windows'"]
sqlalchemy = ["sqlalchemy[asyncio]", "greenlet"]

[dependency-groups]
test = [
"pytest>=8.0.0",
"trio>=0.24.0",
"pytest-cov>=5.0.0",
"aiosqlite>=0.20.0",
"pytest-xdist>=3.6.1",
]
docs = [
"sphinx>=7.1.0",
"readthedocs-sphinx-search>=0.3.2",
"sphinx-rtd-theme>=2.0.0",
"sphinx-mdinclude>=0.5.3",
]

[tool.uv]
managed = true
dev-dependencies = [
dev = [
{ include-group = "test"},
"ruff==0.6.8",
"ipykernel>=6.29.0",
"pre-commit>=3.5.0",
"async_wrapper[uvloop,sqlalchemy,test]",
"poethepoet>=0.27.0",
"async_wrapper[uvloop,sqlalchemy]",
]
docs = [
"linkify-it-py>=2.0.3; python_version < '3.10'",
"myst-parser>=3.0.1; python_version < '3.10'",
"sphinx-autodoc-typehints>=2.3.0; python_version < '3.10'",
"sphinx-immaterial>=0.12.4; python_version < '3.10'",
"sphinx>=7.4.7; python_version < '3.10'",
# 3.10
"linkify-it-py>=2.0.3; python_version >= '3.10'",
"myst-parser>=4.0.0; python_version >= '3.10'",
"sphinx>=8.1.3; python_version >= '3.10'",
"sphinx-autodoc-typehints>=2.5.0; python_version >= '3.10'",
"sphinx-immaterial>=0.12.4; python_version >= '3.10'",
#
"tomli>=2"
]

[tool.uv]
managed = true
default-groups = ["dev"]

[tool.poe.tasks]
html = "make html"
lint = ["_lint:check", "_lint:format"]
check = "pre-commit run --all-files --show-diff-on-failure"
"_lint:check" = "ruff check src --fix"
"_lint:format" = "ruff format src"
check = "pre-commit run --all-files --show-diff-on-failure"

[build-system]
requires = ["hatchling", "hatch-vcs"]
Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ignore = [
"D102",
"PLR2004",
]
"./src/docs/conf.py" = ['E402']
"src/docs/conf.py" = ["INP001", "A001"]

[format]
indent-style = "space"
Expand Down
72 changes: 36 additions & 36 deletions src/async_wrapper/convert/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,29 @@
if TYPE_CHECKING:
from collections.abc import Awaitable, Callable, Coroutine

ValueT = TypeVar("ValueT", infer_variance=True)
ParamT = ParamSpec("ParamT")
_T = TypeVar("_T", infer_variance=True)
_P = ParamSpec("_P")

__all__ = ["sync_to_async"]


class Async(Generic[ParamT, ValueT]):
def __init__(self, func: Callable[ParamT, ValueT]) -> None:
class Async(Generic[_P, _T]):
def __init__(self, func: Callable[_P, _T]) -> None:
self._func = func

@cached_property
def _wrapped(self) -> Callable[ParamT, Coroutine[Any, Any, ValueT]]:
def _wrapped(self) -> Callable[_P, Coroutine[Any, Any, _T]]:
@wraps(self._func)
async def inner(*args: ParamT.args, **kwargs: ParamT.kwargs) -> ValueT:
async def inner(*args: _P.args, **kwargs: _P.kwargs) -> _T:
return await to_thread.run_sync(partial(self._func, *args, **kwargs))

return inner

async def __call__(self, *args: ParamT.args, **kwargs: ParamT.kwargs) -> ValueT:
async def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _T:
return await self._wrapped(*args, **kwargs)


def sync_to_async(
func: Callable[ParamT, ValueT],
) -> Callable[ParamT, Awaitable[ValueT]]:
def sync_to_async(func: Callable[_P, _T]) -> Callable[_P, Awaitable[_T]]:
"""
Convert a synchronous function to an asynchronous function.
Expand All @@ -45,32 +43,34 @@ def sync_to_async(
that behaves equivalently to the input synchronous function.
Example:
>>> import time
>>>
>>> import anyio
>>>
>>> from async_wrapper import sync_to_async
>>>
>>>
>>> @sync_to_async
>>> def test(x: int) -> int:
>>> print(f"[{x}] test: start")
>>> time.sleep(1)
>>> print(f"[{x}] test: end")
>>> return x
>>>
>>>
>>> async def main() -> None:
>>> start = time.perf_counter()
>>> async with anyio.create_task_group() as task_group:
>>> for i in range(4):
>>> task_group.start_soon(test, i)
>>> end = time.perf_counter()
>>> assert end - start < 1.1
>>>
>>>
>>> if __name__ == "__main__":
>>> anyio.run(main)
.. code-block:: python
import time
import anyio
from async_wrapper import sync_to_async
@sync_to_async
def test(x: int) -> int:
print(f"[{x}] test: start")
time.sleep(1)
print(f"[{x}] test: end")
return x
async def main() -> None:
start = time.perf_counter()
async with anyio.create_task_group() as task_group:
for i in range(4):
task_group.start_soon(test, i)
end = time.perf_counter()
assert end - start < 1.1
if __name__ == "__main__":
anyio.run(main)
"""
from async_wrapper.convert._sync.main import Sync

Expand Down
Loading

0 comments on commit b91acc7

Please sign in to comment.