Skip to content

Commit

Permalink
Merge branch 'main' into add_enum_choice
Browse files Browse the repository at this point in the history
  • Loading branch information
saroad2 committed Sep 5, 2023
2 parents 28e0190 + ca5e1c3 commit 0f8868a
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 171 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
outputs:
hash: ${{ steps.hash.outputs.hash }}
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
with:
python-version: '3.x'
Expand All @@ -33,7 +33,7 @@ jobs:
id-token: write
contents: write
# Can't pin with hash due to how this workflow works.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.7.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0
with:
base64-subjects: ${{ needs.build.outputs.hash }}
create-release:
Expand Down Expand Up @@ -62,10 +62,10 @@ jobs:
id-token: write
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a
- uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
with:
repository_url: https://test.pypi.org/legacy/
packages_dir: artifact/
- uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
with:
packages-dir: artifact/
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- {name: 'PyPy', python: 'pypy-3.10', os: ubuntu-latest, tox: pypy310}
- {name: Typing, python: '3.11', os: ubuntu-latest, tox: typing}
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
with:
python-version: ${{ matrix.python }}
Expand Down
11 changes: 7 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Unreleased
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`326`
- Use ``flit_core`` instead of ``setuptools`` as build backend.
- Deprecate the ``__version__`` attribute. Use feature detection, or
``importlib.metadata.version("click")``, instead. :issue:`2598`
- ``BaseCommand`` is deprecated. ``Command`` is the base class for all
commands. :issue:`2589`
- ``MultiCommand`` is deprecated. ``Group`` is the base class for all group
Expand All @@ -26,6 +28,9 @@ Unreleased

- Enable deferred evaluation of annotations with
``from __future__ import annotations``. :pr:`2270`
- When generating a command's name from a decorated function's name, the
suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed.
:issue:`2322`


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

Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,5 @@ Miscellaneous Pages
:maxdepth: 2

contrib
upgrading
license
changes
8 changes: 0 additions & 8 deletions docs/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,6 @@ What it looks like:
invoke(hello)
invoke(hello, args=['--version'])

.. admonition:: Callback Signature Changes

In Click 2.0 the signature for callbacks changed. For more
information about these changes see :ref:`upgrade-to-2.0`.

Yes Parameters
--------------
Expand Down Expand Up @@ -637,10 +633,6 @@ replaced with the :func:`confirmation_option` decorator:
def dropdb():
click.echo('Dropped all tables!')

.. admonition:: Callback Signature Changes

In Click 2.0 the signature for callbacks changed. For more
information about these changes see :ref:`upgrade-to-2.0`.

Values from Environment Variables
---------------------------------
Expand Down
131 changes: 0 additions & 131 deletions docs/upgrading.rst

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[project]
name = "click"
version = "8.2.0.dev"
description = "Composable command line interface toolkit"
readme = "README.rst"
license = {file = "LICENSE.rst"}
Expand All @@ -15,7 +16,6 @@ requires-python = ">=3.8"
dependencies = [
"colorama; platform_system == 'Windows'",
]
dynamic = ["version"]

[project.urls]
Donate = "https://palletsprojects.com/donate"
Expand Down
15 changes: 13 additions & 2 deletions src/click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@
from .utils import get_text_stream as get_text_stream
from .utils import open_file as open_file

__version__ = "8.2.0.dev0"


def __getattr__(name: str) -> object:
import warnings
Expand Down Expand Up @@ -109,4 +107,17 @@ def __getattr__(name: str) -> object:
)
return _OptionParser

if name == "__version__":
import importlib.metadata
import warnings

warnings.warn(
"The '__version__' attribute is deprecated and will be removed in"
" Click 9.1. Use feature detection or"
" 'importlib.metadata.version(\"click\")' instead.",
DeprecationWarning,
stacklevel=2,
)
return importlib.metadata.version("click")

raise AttributeError(name)
8 changes: 3 additions & 5 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,12 @@ def invoke(
(options and click arguments) must be keyword arguments and Click
will fill in defaults.
Note that before Click 3.2 keyword arguments were not properly filled
in against the intention of this code and no context was created. For
more information about this change and why it was done in a bugfix
release see :ref:`upgrade-to-3.2`.
.. versionchanged:: 8.0
All ``kwargs`` are tracked in :attr:`params` so they will be
passed if :meth:`forward` is called at multiple levels.
.. versionchanged:: 3.2
A new context is created, and missing arguments use default values.
"""
if isinstance(__callback, Command):
other_cmd = __callback
Expand Down
34 changes: 21 additions & 13 deletions src/click/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ def command(
callback. This will also automatically attach all decorated
:func:`option`\s and :func:`argument`\s as parameters to the command.
The name of the command defaults to the name of the function with
underscores replaced by dashes. If you want to change that, you can
pass the intended name as the first argument.
The name of the command defaults to the name of the function, converted to
lowercase, with underscores ``_`` replaced by dashes ``-``, and the suffixes
``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed. For example,
``init_data_command`` becomes ``init-data``.
All keyword arguments are forwarded to the underlying command class.
For the ``params`` argument, any decorated params are appended to
Expand All @@ -190,10 +191,13 @@ def command(
that can be invoked as a command line utility or be attached to a
command :class:`Group`.
:param name: the name of the command. This defaults to the function
name with underscores replaced by dashes.
:param cls: the command class to instantiate. This defaults to
:class:`Command`.
:param name: The name of the command. Defaults to modifying the function's
name as described above.
:param cls: The command class to create. Defaults to :class:`Command`.
.. versionchanged:: 8.2
The suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are
removed when generating the name.
.. versionchanged:: 8.1
This decorator can be applied without parentheses.
Expand Down Expand Up @@ -236,12 +240,16 @@ def decorator(f: _AnyCallable) -> CmdType:
assert cls is not None
assert not callable(name)

cmd = cls(
name=name or f.__name__.lower().replace("_", "-"),
callback=f,
params=params,
**attrs,
)
if name is not None:
cmd_name = name
else:
cmd_name = f.__name__.lower().replace("_", "-")
cmd_left, sep, suffix = cmd_name.rpartition("-")

if sep and suffix in {"command", "cmd", "group", "grp"}:
cmd_name = cmd_left

cmd = cls(name=cmd_name, callback=f, params=params, **attrs)
cmd.__doc__ = f.__doc__
return cmd

Expand Down
21 changes: 21 additions & 0 deletions tests/test_command_decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import click


Expand Down Expand Up @@ -69,3 +71,22 @@ def cli(a, b):
assert cli.params[1].name == "b"
result = runner.invoke(cli, ["1", "2"])
assert result.output == "1 2\n"


@pytest.mark.parametrize(
"name",
[
"init_data",
"init_data_command",
"init_data_cmd",
"init_data_group",
"init_data_grp",
],
)
def test_generate_name(name: str) -> None:
def f():
pass

f.__name__ = name
f = click.command(f)
assert f.name == "init-data"
2 changes: 1 addition & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def other_cmd(ctx, a, b, c):
result = runner.invoke(cli, standalone_mode=False)
# invoke should type cast default values, str becomes int, empty
# multiple should be empty tuple instead of None
assert result.return_value == ("other-cmd", 42, 15, ())
assert result.return_value == ("other", 42, 15, ())


def test_invoked_subcommand(runner):
Expand Down

0 comments on commit 0f8868a

Please sign in to comment.