Skip to content

Commit 0f8868a

Browse files
committed
Merge branch 'main' into add_enum_choice
2 parents 28e0190 + ca5e1c3 commit 0f8868a

12 files changed

Lines changed: 72 additions & 171 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
outputs:
1010
hash: ${{ steps.hash.outputs.hash }}
1111
steps:
12-
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
12+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
1313
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
1414
with:
1515
python-version: '3.x'
@@ -33,7 +33,7 @@ jobs:
3333
id-token: write
3434
contents: write
3535
# Can't pin with hash due to how this workflow works.
36-
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.7.0
36+
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0
3737
with:
3838
base64-subjects: ${{ needs.build.outputs.hash }}
3939
create-release:
@@ -62,10 +62,10 @@ jobs:
6262
id-token: write
6363
steps:
6464
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a
65-
- uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8
65+
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
6666
with:
6767
repository_url: https://test.pypi.org/legacy/
6868
packages_dir: artifact/
69-
- uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8
69+
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
7070
with:
7171
packages-dir: artifact/

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- {name: 'PyPy', python: 'pypy-3.10', os: ubuntu-latest, tox: pypy310}
3535
- {name: Typing, python: '3.11', os: ubuntu-latest, tox: typing}
3636
steps:
37-
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
37+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
3838
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
3939
with:
4040
python-version: ${{ matrix.python }}

CHANGES.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Unreleased
99
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
1010
:pr:`326`
1111
- Use ``flit_core`` instead of ``setuptools`` as build backend.
12+
- Deprecate the ``__version__`` attribute. Use feature detection, or
13+
``importlib.metadata.version("click")``, instead. :issue:`2598`
1214
- ``BaseCommand`` is deprecated. ``Command`` is the base class for all
1315
commands. :issue:`2589`
1416
- ``MultiCommand`` is deprecated. ``Group`` is the base class for all group
@@ -26,6 +28,9 @@ Unreleased
2628

2729
- Enable deferred evaluation of annotations with
2830
``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`
2934

3035

3136
Version 8.1.7
@@ -952,12 +957,10 @@ Released 2014-08-22
952957
function.
953958
- Fixed default parameters not being handled properly by the context
954959
invoke method. This is a backwards incompatible change if the
955-
function was used improperly. See :ref:`upgrade-to-3.2` for more
956-
information.
960+
function was used improperly.
957961
- Removed the ``invoked_subcommands`` attribute largely. It is not
958962
possible to provide it to work error free due to how the parsing
959-
works so this API has been deprecated. See :ref:`upgrade-to-3.2` for
960-
more information.
963+
works so this API has been deprecated.
961964
- Restored the functionality of ``invoked_subcommand`` which was
962965
broken as a regression in 3.1.
963966

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,5 @@ Miscellaneous Pages
102102
:maxdepth: 2
103103

104104
contrib
105-
upgrading
106105
license
107106
changes

docs/options.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,6 @@ What it looks like:
594594
invoke(hello)
595595
invoke(hello, args=['--version'])
596596

597-
.. admonition:: Callback Signature Changes
598-
599-
In Click 2.0 the signature for callbacks changed. For more
600-
information about these changes see :ref:`upgrade-to-2.0`.
601597

602598
Yes Parameters
603599
--------------
@@ -637,10 +633,6 @@ replaced with the :func:`confirmation_option` decorator:
637633
def dropdb():
638634
click.echo('Dropped all tables!')
639635

640-
.. admonition:: Callback Signature Changes
641-
642-
In Click 2.0 the signature for callbacks changed. For more
643-
information about these changes see :ref:`upgrade-to-2.0`.
644636

645637
Values from Environment Variables
646638
---------------------------------

docs/upgrading.rst

Lines changed: 0 additions & 131 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[project]
22
name = "click"
3+
version = "8.2.0.dev"
34
description = "Composable command line interface toolkit"
45
readme = "README.rst"
56
license = {file = "LICENSE.rst"}
@@ -15,7 +16,6 @@ requires-python = ">=3.8"
1516
dependencies = [
1617
"colorama; platform_system == 'Windows'",
1718
]
18-
dynamic = ["version"]
1919

2020
[project.urls]
2121
Donate = "https://palletsprojects.com/donate"

src/click/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
from .utils import get_text_stream as get_text_stream
7171
from .utils import open_file as open_file
7272

73-
__version__ = "8.2.0.dev0"
74-
7573

7674
def __getattr__(name: str) -> object:
7775
import warnings
@@ -109,4 +107,17 @@ def __getattr__(name: str) -> object:
109107
)
110108
return _OptionParser
111109

110+
if name == "__version__":
111+
import importlib.metadata
112+
import warnings
113+
114+
warnings.warn(
115+
"The '__version__' attribute is deprecated and will be removed in"
116+
" Click 9.1. Use feature detection or"
117+
" 'importlib.metadata.version(\"click\")' instead.",
118+
DeprecationWarning,
119+
stacklevel=2,
120+
)
121+
return importlib.metadata.version("click")
122+
112123
raise AttributeError(name)

src/click/core.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,12 @@ def invoke(
756756
(options and click arguments) must be keyword arguments and Click
757757
will fill in defaults.
758758
759-
Note that before Click 3.2 keyword arguments were not properly filled
760-
in against the intention of this code and no context was created. For
761-
more information about this change and why it was done in a bugfix
762-
release see :ref:`upgrade-to-3.2`.
763-
764759
.. versionchanged:: 8.0
765760
All ``kwargs`` are tracked in :attr:`params` so they will be
766761
passed if :meth:`forward` is called at multiple levels.
762+
763+
.. versionchanged:: 3.2
764+
A new context is created, and missing arguments use default values.
767765
"""
768766
if isinstance(__callback, Command):
769767
other_cmd = __callback

src/click/decorators.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def command(
178178
callback. This will also automatically attach all decorated
179179
:func:`option`\s and :func:`argument`\s as parameters to the command.
180180
181-
The name of the command defaults to the name of the function with
182-
underscores replaced by dashes. If you want to change that, you can
183-
pass the intended name as the first argument.
181+
The name of the command defaults to the name of the function, converted to
182+
lowercase, with underscores ``_`` replaced by dashes ``-``, and the suffixes
183+
``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed. For example,
184+
``init_data_command`` becomes ``init-data``.
184185
185186
All keyword arguments are forwarded to the underlying command class.
186187
For the ``params`` argument, any decorated params are appended to
@@ -190,10 +191,13 @@ def command(
190191
that can be invoked as a command line utility or be attached to a
191192
command :class:`Group`.
192193
193-
:param name: the name of the command. This defaults to the function
194-
name with underscores replaced by dashes.
195-
:param cls: the command class to instantiate. This defaults to
196-
:class:`Command`.
194+
:param name: The name of the command. Defaults to modifying the function's
195+
name as described above.
196+
:param cls: The command class to create. Defaults to :class:`Command`.
197+
198+
.. versionchanged:: 8.2
199+
The suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are
200+
removed when generating the name.
197201
198202
.. versionchanged:: 8.1
199203
This decorator can be applied without parentheses.
@@ -236,12 +240,16 @@ def decorator(f: _AnyCallable) -> CmdType:
236240
assert cls is not None
237241
assert not callable(name)
238242

239-
cmd = cls(
240-
name=name or f.__name__.lower().replace("_", "-"),
241-
callback=f,
242-
params=params,
243-
**attrs,
244-
)
243+
if name is not None:
244+
cmd_name = name
245+
else:
246+
cmd_name = f.__name__.lower().replace("_", "-")
247+
cmd_left, sep, suffix = cmd_name.rpartition("-")
248+
249+
if sep and suffix in {"command", "cmd", "group", "grp"}:
250+
cmd_name = cmd_left
251+
252+
cmd = cls(name=cmd_name, callback=f, params=params, **attrs)
245253
cmd.__doc__ = f.__doc__
246254
return cmd
247255

0 commit comments

Comments
 (0)