Skip to content

Commit f68161b

Browse files
committed
Merge branch 'main' into bugfix/OptionsAutoCompletion
2 parents f08e133 + 8fcf9b0 commit f68161b

86 files changed

Lines changed: 4029 additions & 2957 deletions

Some content is hidden

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

.github/workflows/pre-commit.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pre-commit
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main, stable]
6+
jobs:
7+
main:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
11+
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
12+
with:
13+
python-version: 3.x
14+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
15+
- uses: pre-commit-ci/lite-action@9d882e7a565f7008d4faf128f27d1cb6503d4ebf # v1.0.2
16+
if: ${{ !cancelled() }}

.github/workflows/tests.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- {python: '3.10'}
2222
- {python: '3.9'}
2323
- {python: '3.8'}
24-
- {python: '3.7'}
2524
- {name: PyPy, python: 'pypy-3.10', tox: pypy310}
2625
steps:
2726
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
.vscode/
33
.venv*/
44
venv*/
5+
.env*/
6+
env*/
57
__pycache__/
68
dist/
79
.coverage*

CHANGES.rst

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,104 @@
11
.. currentmodule:: click
22

3+
Version 8.2.0
4+
-------------
5+
6+
Unreleased
7+
8+
- Drop support for Python 3.7. :pr:`2588`
9+
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
10+
:pr:`2438`
11+
- Use ``flit_core`` instead of ``setuptools`` as build backend. :pr:`2543`
12+
- Deprecate the ``__version__`` attribute. Use feature detection, or
13+
``importlib.metadata.version("click")``, instead. :issue:`2598`
14+
- ``BaseCommand`` is deprecated. ``Command`` is the base class for all
15+
commands. :issue:`2589`
16+
- ``MultiCommand`` is deprecated. ``Group`` is the base class for all group
17+
commands. :issue:`2590`
18+
- The current parser and related classes and methods, are deprecated.
19+
:issue:`2205`
20+
21+
- ``OptionParser`` and the ``parser`` module, which is a modified copy of
22+
``optparse`` in the standard library.
23+
- ``Context.protected_args`` is unneeded. ``Context.args`` contains any
24+
remaining arguments while parsing.
25+
- ``Parameter.add_to_parser`` (on both ``Argument`` and ``Option``) is
26+
unneeded. Parsing works directly without building a separate parser.
27+
- ``split_arg_string`` is moved from ``parser`` to ``shell_completion``.
28+
29+
- Enable deferred evaluation of annotations with
30+
``from __future__ import annotations``. :pr:`2270`
31+
- When generating a command's name from a decorated function's name, the
32+
suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed.
33+
:issue:`2322`
34+
- Show the ``types.ParamType.name`` for ``types.Choice`` options within
35+
``--help`` message if ``show_choices=False`` is specified.
36+
:issue:`2356`
37+
- Do not display default values in prompts when ``Option.show_default`` is
38+
``False``. :pr:`2509`
39+
- Add ``get_help_extra`` method on ``Option`` to fetch the generated extra
40+
items used in ``get_help_record`` to render help text. :issue:`2516`
41+
:pr:`2517`
42+
- Keep stdout and stderr streams independent in ``CliRunner``. Always
43+
collect stderr output and never raise an exception. Add a new
44+
output stream to simulate what the user sees in its terminal. Removes
45+
the ``mix_stderr`` parameter in ``CliRunner``. :issue:`2522` :pr:`2523`
46+
- ``Option.show_envvar`` now also shows environment variable in error messages.
47+
:issue:`2695` :pr:`2696`
48+
- ``Context.close`` will be called on exit. This results in all
49+
``Context.call_on_close`` callbacks and context managers added via
50+
``Context.with_resource`` to be closed on exit as well. :pr:`2680`
51+
- Add ``ProgressBar(hidden: bool)`` to allow hiding the progressbar. :issue:`2609`
52+
- A ``UserWarning`` will be shown when multiple parameters attempt to use the
53+
same name. :issue:`2396`
54+
- When using ``Option.envvar`` with ``Option.flag_value``, the ``flag_value``
55+
will always be used instead of the value of the environment variable.
56+
:issue:`2746` :pr:`2788`
57+
- Add ``Choice.get_invalid_choice_message`` method for customizing the
58+
invalid choice message. :issue:`2621` :pr:`2622`
59+
- If help is shown because ``no_args_is_help`` is enabled (defaults to ``True``
60+
for groups, ``False`` for commands), the exit code is 2 instead of 0.
61+
:issue:`1489` :pr:`1489`
62+
- Contexts created during shell completion are closed properly, fixing
63+
a ``ResourceWarning`` when using ``click.File``. :issue:`2644` :pr:`2800`
64+
:pr:`2767`
65+
- ``click.edit(filename)`` now supports passing an iterable of filenames in
66+
case the editor supports editing multiple files at once. Its return type
67+
is now also typed: ``AnyStr`` if ``text`` is passed, otherwise ``None``.
68+
:issue:`2067` :pr:`2068`
69+
- Specialized typing of ``progressbar(length=...)`` as ``ProgressBar[int]``.
70+
:pr:`2630`
71+
- Improve ``echo_via_pager`` behaviour in face of errors.
72+
:issue:`2674`
73+
74+
- Terminate the pager in case a generator passed to ``echo_via_pager``
75+
raises an exception.
76+
- Ensure to always close the pipe to the pager process and wait for it
77+
to terminate.
78+
- ``echo_via_pager`` will not ignore ``KeyboardInterrupt`` anymore. This
79+
allows the user to search for future output of the generator when
80+
using less and then aborting the program using ctrl-c.
81+
82+
- ``deprecated: bool | str`` can now be used on options and arguments. This
83+
previously was only available for ``Command``. The message can now also be
84+
customised by using a ``str`` instead of a ``bool``. :issue:`2263` :pr:`2271`
85+
86+
- ``Command.deprecated`` formatting in ``--help`` changed from
87+
``(Deprecated) help`` to ``help (DEPRECATED)``.
88+
- Parameters cannot be required nor prompted or an error is raised.
89+
- A warning will be printed when something deprecated is used.
90+
91+
- Add a ``catch_exceptions`` parameter to ``CliRunner``. If
92+
``catch_exceptions`` is not passed to ``CliRunner.invoke``,
93+
the value from ``CliRunner``. :issue:`2817` :pr:`2818`
94+
- ``Option.flag_value`` will no longer have a default value set based on
95+
``Option.default`` if ``Option.is_flag`` is ``False``. This results in
96+
``Option.default`` not needing to implement `__bool__`. :pr:`2829`
97+
- Incorrect ``click.edit`` typing has been corrected. :pr:`2804`
98+
- ``Choice`` is now generic and supports any iterable value.
99+
This allows you to use enums and other non-``str`` values. :pr:`2796`
100+
:issue:`605`
101+
3102
Version 8.1.8
4103
-------------
5104

@@ -957,12 +1056,10 @@ Released 2014-08-22
9571056
function.
9581057
- Fixed default parameters not being handled properly by the context
9591058
invoke method. This is a backwards incompatible change if the
960-
function was used improperly. See :ref:`upgrade-to-3.2` for more
961-
information.
1059+
function was used improperly.
9621060
- Removed the ``invoked_subcommands`` attribute largely. It is not
9631061
possible to provide it to work error free due to how the parsing
964-
works so this API has been deprecated. See :ref:`upgrade-to-3.2` for
965-
more information.
1062+
works so this API has been deprecated.
9661063
- Restored the functionality of ``invoked_subcommand`` which was
9671064
broken as a regression in 3.1.
9681065

CONTRIBUTING.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ First time setup
107107
108108
> env\Scripts\activate
109109
110-
- Upgrade pip and setuptools.
111-
112-
.. code-block:: text
113-
114-
$ python -m pip install --upgrade pip setuptools
115-
116110
- Install the development dependencies, then install Click in
117111
editable mode.
118112

docs/advanced.rst

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,74 @@ In addition to common functionality that is implemented in the library
77
itself, there are countless patterns that can be implemented by extending
88
Click. This page should give some insight into what can be accomplished.
99

10+
1011
.. _aliases:
1112

1213
Command Aliases
1314
---------------
1415

15-
Many tools support aliases for commands (see `Command alias example
16-
<https://github.com/pallets/click/tree/main/examples/aliases>`_).
17-
For instance, you can configure ``git`` to accept ``git ci`` as alias for
18-
``git commit``. Other tools also support auto-discovery for aliases by
19-
automatically shortening them.
20-
21-
Click does not support this out of the box, but it's very easy to customize
22-
the :class:`Group` or any other :class:`MultiCommand` to provide this
23-
functionality.
16+
Many tools support aliases for commands. For example, you can configure
17+
``git`` to accept ``git ci`` as alias for ``git commit``. Other tools also
18+
support auto-discovery for aliases by automatically shortening them.
2419

25-
As explained in :ref:`custom-multi-commands`, a multi command can provide
26-
two methods: :meth:`~MultiCommand.list_commands` and
27-
:meth:`~MultiCommand.get_command`. In this particular case, you only need
28-
to override the latter as you generally don't want to enumerate the
29-
aliases on the help page in order to avoid confusion.
20+
It's possible to customize :class:`Group` to provide this functionality. As
21+
explained in :ref:`custom-groups`, a group provides two methods:
22+
:meth:`~Group.list_commands` and :meth:`~Group.get_command`. In this particular
23+
case, you only need to override the latter as you generally don't want to
24+
enumerate the aliases on the help page in order to avoid confusion.
3025

31-
This following example implements a subclass of :class:`Group` that
32-
accepts a prefix for a command. If there were a command called ``push``,
33-
it would accept ``pus`` as an alias (so long as it was unique):
26+
The following example implements a subclass of :class:`Group` that accepts a
27+
prefix for a command. If there was a command called ``push``, it would accept
28+
``pus`` as an alias (so long as it was unique):
3429

3530
.. click:example::
3631
3732
class AliasedGroup(click.Group):
3833
def get_command(self, ctx, cmd_name):
39-
rv = click.Group.get_command(self, ctx, cmd_name)
34+
rv = super().get_command(ctx, cmd_name)
35+
4036
if rv is not None:
4137
return rv
42-
matches = [x for x in self.list_commands(ctx)
43-
if x.startswith(cmd_name)]
38+
39+
matches = [
40+
x for x in self.list_commands(ctx)
41+
if x.startswith(cmd_name)
42+
]
43+
4444
if not matches:
4545
return None
46-
elif len(matches) == 1:
46+
47+
if len(matches) == 1:
4748
return click.Group.get_command(self, ctx, matches[0])
49+
4850
ctx.fail(f"Too many matches: {', '.join(sorted(matches))}")
4951

5052
def resolve_command(self, ctx, args):
5153
# always return the full command name
5254
_, cmd, args = super().resolve_command(ctx, args)
5355
return cmd.name, cmd, args
5456

55-
And it can then be used like this:
57+
It can be used like this:
5658

5759
.. click:example::
5860
59-
@click.command(cls=AliasedGroup)
61+
@click.group(cls=AliasedGroup)
6062
def cli():
6163
pass
6264

63-
@cli.command()
65+
@cli.command
6466
def push():
6567
pass
6668

67-
@cli.command()
69+
@cli.command
6870
def pop():
6971
pass
7072

73+
See the `alias example`_ in Click's repository for another example.
74+
75+
.. _alias example: https://github.com/pallets/click/tree/main/examples/aliases
76+
77+
7178
Parameter Modifications
7279
-----------------------
7380

@@ -266,7 +273,7 @@ triggering a parsing error.
266273
This can generally be activated in two different ways:
267274

268275
1. It can be enabled on custom :class:`Command` subclasses by changing
269-
the :attr:`~BaseCommand.ignore_unknown_options` attribute.
276+
the :attr:`~Command.ignore_unknown_options` attribute.
270277
2. It can be enabled by changing the attribute of the same name on the
271278
context class (:attr:`Context.ignore_unknown_options`). This is best
272279
changed through the ``context_settings`` dictionary on the command.
@@ -487,3 +494,8 @@ cleanup function.
487494
db.record_use()
488495
db.save()
489496
db.close()
497+
498+
499+
.. versionchanged:: 8.2 ``Context.call_on_close`` and context managers registered
500+
via ``Context.with_resource`` will be closed when the CLI exits. These were
501+
previously not called on exit.

docs/api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Context
113113
:members:
114114
:member-order: bysource
115115

116+
.. _click-api-types:
116117

117118
Types
118119
-----
@@ -134,6 +135,7 @@ Types
134135
.. autoclass:: Path
135136

136137
.. autoclass:: Choice
138+
:members:
137139

138140
.. autoclass:: IntRange
139141

0 commit comments

Comments
 (0)