Skip to content

Commit 3edda19

Browse files
committed
Fix hard dependency on anyio
1 parent 30cfa61 commit 3edda19

File tree

3 files changed

+132
-17
lines changed

3 files changed

+132
-17
lines changed

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ classifiers = [
1515
requires-python = ">=3.10"
1616
dependencies = [
1717
"colorama; platform_system == 'Windows'",
18-
"anyio ~= 4.0",
1918
]
20-
version = "8.3.0.1"
19+
version = "8.3.0.2"
2120

2221
[project.urls]
2322
Donate = "https://palletsprojects.com/donate"
@@ -50,13 +49,21 @@ pre-commit = [
5049
"pre-commit-uv",
5150
]
5251
tests = [
52+
"anyio",
5353
"pytest",
5454
]
5555
typing = [
56+
"anyio",
5657
"mypy",
5758
"pyright",
5859
"pytest",
5960
]
61+
anyio = [
62+
"anyio ~= 4.0",
63+
]
64+
trio = [
65+
"trio ~= 0.22",
66+
]
6067

6168
[build-system]
6269
requires = ["flit_core<4"]

src/asyncclick/core.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from itertools import repeat
2121
from types import TracebackType
2222

23-
import anyio
24-
2523
from . import types
2624
from ._utils import FLAG_NEEDS_VALUE
2725
from ._utils import UNSET
@@ -1540,16 +1538,31 @@ def __call__(
15401538
"""
15411539
main = self.main
15421540
opts: dict[str, t.Any] = {}
1543-
if _anyio_backend:
1544-
opts["backend"] = _anyio_backend
1545-
if _anyio_backend_options:
1546-
opts["backend_options"] = _anyio_backend_options
1547-
return anyio.run(self.main, main, args, kwargs, **opts) # type:ignore
1541+
try:
1542+
import anyio
1543+
except ImportError:
1544+
pass
1545+
else:
1546+
if _anyio_backend:
1547+
opts["backend"] = _anyio_backend
1548+
if _anyio_backend_options:
1549+
opts["backend_options"] = _anyio_backend_options
1550+
return anyio.run(self.main, main, args, kwargs, **opts) # type:ignore
1551+
1552+
if _anyio_backend == "trio":
1553+
import trio
1554+
1555+
return trio.run(self._main, main, args, kwargs)
1556+
if _anyio_backend == "asyncio":
1557+
import asyncio
1558+
1559+
return asyncio.run(self._main(main, args, kwargs))
1560+
raise RuntimeError(f"Backend {_anyio_backend!r} unknown")
15481561

15491562
async def _main(
15501563
self,
15511564
main: t.Callable[..., t.Awaitable[t.Any]],
1552-
args: list[t.Any],
1565+
args: t.Sequence[t.Any],
15531566
kwargs: dict[str, t.Any],
15541567
) -> t.Any:
15551568
return await main(*args, **kwargs)

uv.lock

Lines changed: 102 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)