Skip to content

Commit cd56c48

Browse files
committed
Merge branch 'main' into deb
2 parents 21f549e + b69dfe6 commit cd56c48

86 files changed

Lines changed: 4290 additions & 2298 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
/.idea/
2-
/.vscode/
1+
src/*.egg-info/
2+
/.hypothesis/
3+
/build/
34
/.pybuild/
45
.cache/
6+
/.idea/
7+
/.vscode/
8+
/env/
9+
/venv/
510
__pycache__/
611
*.pyc
7-
*.egg-info/
12+
/docs/_build/
13+
/.eggs/
14+
/htmlcov/
15+
*.pyc
816
/build/
917
/dist/
1018
/.pytest_cache/
19+
/.tox/
1120
.coverage
1221
.coverage.*
13-
htmlcov/
14-
/docs/_build/
15-
/.eggs/
16-
.coverage*
17-
.tox/
22+
/htmlcov/
23+
dist/
1824
docs/_build/

CHANGES.rst

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,48 @@ asyncclick 8
1414
``@asyncclick.async_backend(NAME)`` decorator. The old method of setting
1515
``asyncclick.anyio_backend=NAME`` still works.
1616

17+
Version 8.3.0
18+
--------------
19+
20+
Released 2025-09-15
21+
22+
- **Important: Breaking asyncclick change**: :func:`asyncclick.prompt` is now
23+
async. It accepts a new `blocking` parameter to switch between keeping the
24+
async loop running (`False`) and not going belly-up when the user interrupts
25+
it using Control-C (`True`). `True` thus is the default (for now).
26+
27+
- **Improved flag option handling**: Reworked the relationship between ``flag_value``
28+
and ``default`` parameters for better consistency:
29+
30+
* The ``default`` parameter value is now preserved as-is and passed directly
31+
to CLI functions (no more unexpected transformations)
32+
* Exception: flag options with ``default=True`` maintain backward compatibility
33+
by defaulting to their ``flag_value``
34+
* The ``default`` parameter can now be any type (``bool``, ``None``, etc.)
35+
* Fixes inconsistencies reported in: :issue:`1992` :issue:`2514` :issue:`2610`
36+
:issue:`3024` :pr:`3030`
37+
- Allow ``default`` to be set on ``Argument`` for ``nargs = -1``. :issue:`2164`
38+
:pr:`3030`
39+
- Show correct auto complete value for ``nargs`` option in combination with flag
40+
option :issue:`2813`
41+
- Show correct auto complete value for nargs option in combination with flag option :issue:`2813`
42+
- Fix handling of quoted and escaped parameters in Fish autocompletion. :issue:`2995` :pr:`3013`
43+
- Lazily import ``shutil``. :pr:`3023`
44+
- Properly forward exception information to resources registered with
45+
``click.core.Context.with_resource()``. :issue:`2447` :pr:`3058`
46+
- Fix regression related to EOF handling in CliRunner. :issue:`2939`:pr:`2940`
47+
1748
Version 8.2.2
1849
-------------
1950

2051
Released 2025-07-31
2152

22-
- Fix reconciliation of `default`, `flag_value` and `type` parameters for
53+
- Fix reconciliation of ``default``, ``flag_value`` and ``type`` parameters for
2354
flag options, as well as parsing and normalization of environment variables.
2455
:issue:`2952` :pr:`2956`
2556
- Fix typing issue in ``BadParameter`` and ``MissingParameter`` exceptions for the
2657
parameter ``param_hint`` that did not allow for a sequence of string where the
27-
underlying functino ``_join_param_hints`` allows for it. :issue:`2777` :pr:`2990`
58+
underlying function ``_join_param_hints`` allows for it. :issue:`2777` :pr:`2990`
2859
- Use the value of ``Enum`` choices to render their default value in help
2960
screen. Refs :issue:`2911` :pr:`3004`
3061
- Fix completion for the Z shell (``zsh``) for completion items containing

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/make -f
2+
3+
PACKAGE=asyncclick
4+
ifneq ($(wildcard /usr/share/sourcemgr/make/py),)
5+
include /usr/share/sourcemgr/make/py
6+
# available via http://github.com/smurfix/sourcemgr
7+
8+
else
9+
%:
10+
@echo "Please use 'python setup.py'."
11+
@exit 1
12+
endif
13+

README.md

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
<div align="center"><img src="https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg" alt="" height="150"></div>
1+
# $ asyncclick_
2+
3+
Asyncclick is a fork of Click (described below) that works with trio or asyncio.
24

3-
# AsyncClick
5+
AsyncClick allows you to seamlessly use async command and subcommand handlers.
46

5-
[AsyncClick][] is a fork of Click that works well with [anyio][], [Trio][], or [asyncio][].
67

7-
[anyio]: https://anyio.readthedocs.io/en/stable/
8-
[Trio]: https://trio.readthedocs.io/en/stable/
9-
[asyncio]: https://docs.python.org/3/library/asyncio.html
10-
[AsyncClick]: https://github.com/python-trio/asyncclick/
8+
<div align="center"><img src="https://raw.githubusercontent.com/pallets/click/refs/heads/stable/docs/_static/click-name.svg" alt="" height="150"></div>
119

1210
# Click
1311

@@ -20,12 +18,11 @@ It aims to make the process of writing command line tools quick and fun
2018
while also preventing any frustration caused by the inability to
2119
implement an intended CLI API.
2220

23-
AsyncClick in four points:
21+
Click in three points:
2422

2523
- Arbitrary nesting of commands
2624
- Automatic help page generation
2725
- Supports lazy loading of subcommands at runtime
28-
- Seamlessly use async-enabled command and subcommand handlers
2926

3027

3128
## A Simple Example
@@ -39,13 +36,13 @@ import anyio
3936
@click.option("--name", prompt="Your name", help="The person to greet.")
4037
async def hello(count, name):
4138
"""Simple program that greets NAME for a total of COUNT times."""
42-
for x in range(count):
43-
if x:
44-
await anyio.sleep(0.1)
39+
for _ in range(count):
4540
click.echo(f"Hello, {name}!")
41+
await anyio.sleep(0.2)
4642

4743
if __name__ == '__main__':
4844
hello()
45+
# alternately: anyio.run(hello.main)
4946
```
5047

5148
```
@@ -56,15 +53,28 @@ Hello, Click!
5653
Hello, Click!
5754
```
5855

59-
Compared to the original [Click][], you'll note that AsyncClick supports
60-
optional(!) sprinkling of `async`/`await` keywords wherever your code needs
61-
them.
56+
## Differences to Click
57+
58+
This async-ized version of Click is mostly backwards compatible for "normal" use:
59+
you can freely mix sync and async versions of your command handlers and callbacks.
6260

63-
In the interest of not diverging from Click more than absolutely necessary,
64-
many examples have not been touched.
61+
Several advanced methods, most notably :meth:`BaseCommand.main`, and
62+
:meth:`Context.invoke`, are now asynchronous.
6563

64+
The :meth:`BaseCommand.__call__` alias now invokes the main entry point via
65+
`anyio.run`. If you already have an async main program, simply use
66+
``await cmd.main()`` instead of ``cmd()``.
67+
68+
:func:`asyncclick.prompt` is asyncronous and accepts a ``blocking`` parameter
69+
that switches between "doesn't affect your event loop but has unwanted effects when
70+
interrupted" (bugfix pending) and "pauses your event loop but is safe to interrupt"
71+
with Control-C". The latter is the default until we fix that bug.
72+
73+
You cannot use Click and AsyncClick in the same program. This is not a problem
74+
in practice, as replacing ``import click`` with ``import asyncclick as click``, and
75+
``from click import ...`` with ``from asyncclick import ...``, should be all that's
76+
required.
6677

67-
[Click]: https://palletsprojects.com/p/click/
6878

6979
## Donate
7080

@@ -76,13 +86,29 @@ donate today][].
7686
[please donate today]: https://palletsprojects.com/donate
7787

7888
The AsyncClick fork is maintained by Matthias Urlichs <matthias@urlichs.de>.
79-
It's not a lot of work, so if you'd like to motivate me, donate to the
80-
charity of your choice and tell me that you've done so. ;-)
8189

8290
## Contributing
8391

92+
### Click
93+
8494
See our [detailed contributing documentation][contrib] for many ways to
8595
contribute, including reporting issues, requesting features, asking or answering
8696
questions, and making PRs.
8797

8898
[contrib]: https://palletsprojects.com/contributing/
99+
100+
### AsyncClick
101+
102+
You can file async-specific issues, ideally including a corresponding fix,
103+
to the [MoaT/asyncclick][moat] repository on github.
104+
105+
[moat]: https://github.com/M-o-a-T/asyncclick
106+
107+
#### Testing
108+
109+
If you find a bug, please add a testcase to prevent it from recurring.
110+
111+
In tests, you might wonder why `runner.invoke` is not called asynchronously.
112+
The reason is that there are far too many of these calls to modify them all.
113+
Thus ``tests/conftest.py`` contains a monkeypatch that turns this call
114+
into a thread that runs this call using `anyio.run`.

asyncclick

Lines changed: 0 additions & 1 deletion
This file was deleted.

debian/changelog

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1+
asyncclick (1:8.3.0.0-1) unstable; urgency=medium
2+
3+
* Merge
4+
5+
-- Matthias Urlichs <matthias@urlichs.de> Thu, 02 Oct 2025 18:32:52 +0200
6+
17
asyncclick (1:8.2.2+anyio.1-1) unstable; urgency=medium
28

39
* Merge
410

511
-- Matthias Urlichs <matthias@urlichs.de> Wed, 13 Aug 2025 17:26:28 +0200
612

13+
asyncclick (1:8.1.8-1) unstable; urgency=medium
14+
15+
* new Upstream
16+
17+
-- Matthias Urlichs <matthias@urlichs.de> Mon, 06 Jan 2025 10:42:05 +0100
18+
19+
asyncclick (1:8.1.7-2) unstable; urgency=medium
20+
21+
* Fixups
22+
23+
-- Matthias Urlichs <matthias@urlichs.de> Sun, 10 Mar 2024 10:28:31 +0100
24+
25+
asyncclick (1:8.1.3-2) unstable; urgency=medium
26+
27+
* new Upstream
28+
29+
-- Matthias Urlichs <matthias@urlichs.de> Tue, 07 Jun 2022 18:53:38 +0200
30+
731
asyncclick (1:8.0.0a2+anyio.7-1) unstable; urgency=medium
832

933
* Merge
@@ -34,6 +58,42 @@ asyncclick (1:8.0.0a2+anyio.1-1) unstable; urgency=medium
3458

3559
-- Matthias Urlichs <matthias@urlichs.de> Sun, 07 Feb 2021 16:03:11 +0100
3660

61+
asyncclick (1:8.0.3-6) unstable; urgency=medium
62+
63+
* fix test
64+
65+
-- Matthias Urlichs <matthias@urlichs.de> Sat, 15 Jan 2022 22:22:34 +0100
66+
67+
asyncclick (1:8.0.3-5) unstable; urgency=medium
68+
69+
* enter_context => with_resource
70+
71+
-- Matthias Urlichs <matthias@urlichs.de> Sat, 15 Jan 2022 22:21:09 +0100
72+
73+
asyncclick (1:8.0.3-4) unstable; urgency=medium
74+
75+
* missed anyio markers
76+
77+
-- Matthias Urlichs <matthias@urlichs.de> Wed, 05 Jan 2022 11:44:55 +0100
78+
79+
asyncclick (1:8.0.3-3) unstable; urgency=medium
80+
81+
* missed a comflict marker
82+
83+
-- Matthias Urlichs <matthias@urlichs.de> Wed, 05 Jan 2022 11:43:07 +0100
84+
85+
asyncclick (1:8.0.3-2) unstable; urgency=medium
86+
87+
* Fixed PYTHONPATH for tests
88+
89+
-- Matthias Urlichs <matthias@urlichs.de> Wed, 05 Jan 2022 11:42:14 +0100
90+
91+
asyncclick (1:8.0.3-1) unstable; urgency=medium
92+
93+
* Merge 8.0.3
94+
95+
-- Matthias Urlichs <matthias@urlichs.de> Wed, 05 Jan 2022 11:33:57 +0100
96+
3797
asyncclick (1:7.0.90-1) unstable; urgency=medium
3898

3999
* Merge current 7.1

debian/rules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,3 @@ export PYBUILD_NAME=asyncclick
66
%:
77
dh $@ --with python3 --buildsystem=pybuild
88

9-
override_dh_auto_test:
10-
env PYTHONPATH=src python3 -mpytest -sxv tests/
11-

docs/advanced.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Advanced Patterns
22
=================
33

4-
.. currentmodule:: asyncclick
4+
.. currentmodule:: click
55

66
In addition to common functionality, Click offers some advanced features.
77

@@ -38,18 +38,21 @@ Here's an example for a ``--version`` flag:
3838

3939
.. click:example::
4040
41-
def print_version(ctx, param, value):
41+
async def print_version(ctx, param, value):
4242
if not value or ctx.resilient_parsing:
4343
return
4444
click.echo('Version 1.0')
45-
ctx.exit()
45+
ctx.aexit()
4646

4747
@click.command()
4848
@click.option('--version', is_flag=True, callback=print_version,
4949
expose_value=False, is_eager=True)
5050
def hello():
5151
click.echo('Hello World!')
5252

53+
(Note that ``ctx.exit`` is asynchronous in asyncclick, and has thus been renamed.
54+
Alternately you can use ``sys.exit``.)
55+
5356
The `expose_value` parameter prevents the pretty pointless ``version``
5457
parameter from being passed to the callback. If that was not specified, a
5558
boolean would be passed to the `hello` script. The `resilient_parsing`
@@ -222,7 +225,7 @@ Example:
222225
@cli.command()
223226
@click.option('--count', default=1)
224227
@click.pass_context
225-
async def dist(ctx, count):
228+
def dist(ctx, count):
226229
await ctx.forward(test)
227230
await ctx.invoke(test, count=42)
228231

@@ -366,7 +369,7 @@ Ordinarily, it would be used with the ``with`` statement:
366369
However, a ``with`` block in a group would exit and close the database
367370
before it could be used by a subcommand.
368371

369-
Instead, use the context's :meth:`~asyncclick.Context.with_resource` method
372+
Instead, use the context's :meth:`~click.Context.with_resource` method
370373
to enter the context manager and return the resource. When the group and
371374
any subcommands finish, the context's resources are cleaned up.
372375

@@ -385,12 +388,9 @@ any subcommands finish, the context's resources are cleaned up.
385388
for entry in obj.db.query(...):
386389
click.echo(entry)
387390
388-
There is also a :meth:`~asyncclick.Context.with_async_resource` method
389-
if the resource must be used asynchronously.
390-
391391
If the resource isn't a context manager, usually it can be wrapped in
392392
one using something from :mod:`contextlib`. If that's not possible, use
393-
the context's :meth:`~asyncclick.Context.call_on_close` method to register a
393+
the context's :meth:`~click.Context.call_on_close` method to register a
394394
cleanup function.
395395

396396
.. code-block:: python
@@ -407,7 +407,6 @@ cleanup function.
407407
db.save()
408408
db.close()
409409
410-
This method also accepts async close procedures.
411410
412411
.. versionchanged:: 8.2 ``Context.call_on_close`` and context managers registered
413412
via ``Context.with_resource`` will be closed when the CLI exits. These were

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Decorators
3535

3636
.. autofunction:: make_pass_decorator
3737

38-
.. autofunction:: click.decorators.pass_meta_key
38+
.. autofunction:: asyncclick.decorators.pass_meta_key
3939

4040

4141
Utilities

docs/arguments.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Arguments
44
=========
55

6-
.. currentmodule:: asyncclick
6+
.. currentmodule:: click
77

88
Arguments are:
99

0 commit comments

Comments
 (0)