Skip to content
Myr

Merge branch '8.1.x'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parents e16088a, aca1a0c · Browse files · 24 files+247 added−185 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

24 files+247 added−185 removed

  • tests:+45 added−2 removed
  • other:+202 added−183 removed

24 files+247 added−185 removed

modified:.github/workflows/publish.yaml+1 added-1 removed
deleted:.github/dependabot.yml-18 removed
modified:docs/advanced.rst+1 added
440 unmodified lines
441442 def __enter__(self):443 path = os.path.join(self.home, "repo.db")444 self.db = open_database(path)445 return self446447 def __exit__(self, exc_type, exc_value, tb):448 self.db.close()449
47 unmodified lines
modified:docs/conf.py+2 added-2 removed
21 unmodified lines
22autodoc_member_order = "bysource"23autodoc_typehints = "description"24autodoc_preserve_defaults = True25extlinks = {26 "issue": ("https://github.com/pallets/flask/issues/%s", "#%s"),27 "pr": ("https://github.com/pallets/flask/pull/%s", "#%s"),26 "issue": ("https://github.com/pallets/click/issues/%s", "#%s"),27 "pr": ("https://github.com/pallets/click/pull/%s", "#%s"),28}29intersphinx_mapping = {30 "python": ("https://docs.python.org/3/", None),31}
24 unmodified lines
modified:docs/shell-completion.rst+14 added-10 removed
26 unmodified lines
27through an entry point, not through the ``python`` command. See28:doc:`entry-points`. Once the executable is installed, calling it with29a special environment variable will put Click in completion mode.3031In order for completion to be used, the user needs to register a special32function with their shell. The script is different for every shell, and33Click will output it when called with ``_{PROG_NAME}_COMPLETE`` set to34``{shell}_source``. ``{PROG_NAME}`` is the executable name in uppercase35with dashes replaced by underscores. The built-in shells are ``bash``,36``zsh``, and ``fish``.31To enable shell completion, the user needs to register a special32function with their shell. The exact script varies depending on the33shell you are using. Click will output it when called with34``_{FOO_BAR}_COMPLETE`` set to ``{shell}_source``. ``{FOO_BAR}`` is35the executable name in uppercase with dashes replaced by underscores.36It is conventional but not strictly required for environment variable37names to be in upper case. This convention helps distinguish environment38variables from regular shell variables and commands, making scripts39and configuration files more readable and easier to maintain. The40built-in shells are ``bash``, ``zsh``, and ``fish``.4142Provide your users with the following instructions customized to your43program name. This uses ``foo-bar`` as an example.44
152 unmodified lines
197require implementing some smaller parts.198199First, you'll need to figure out how your shell's completion system200works and write a script to integrate it with Click. It must invoke your197program with the environment variable ``_{PROG_NAME}_COMPLETE`` set to201program with the environment variable ``_{FOO_BAR}_COMPLETE`` set to202``{shell}_complete`` and pass the complete args and incomplete value.203How it passes those values, and the format of the completion response204from Click is up to you.205
4 unmodified lines
210- ``complete_func`` - A safe name for the completion function defined211 in the script.212- ``complete_var`` - The environment variable name for passing the213 ``{shell}_complete`` instruction.210- ``prog_name`` - The name of the executable being completed.214- ``foo_bar`` - The name of the executable being completed.215216The example code is for a made up shell "My Shell" or "mysh" for short.217218.. code-block:: python
2 unmodified lines
221 from click.shell_completion import ShellComplete222223 _mysh_source = """\224 %(complete_func)s {221 response=$(%(complete_var)s=mysh_complete %(prog_name)s)225 response=$(%(complete_var)s=mysh_complete %(foo_bar)s)226 # parse response and set completions somehow227 }224 call-on-complete %(prog_name)s %(complete_func)s228 call-on-complete %(foo_bar)s %(complete_func)s229 """230231 @add_completion_class232 class MyshComplete(ShellComplete):
59 unmodified lines
modified:requirements/build.txt+2 added-2 removed
4 unmodified lines
5# pip-compile build.in6#7build==1.2.18 # via -r build.in9packaging==24.09packaging==24.110 # via build11pyproject-hooks==1.0.011pyproject-hooks==1.1.012 # via build
modified:requirements/dev.txt+74 added-102 removed
2 unmodified lines
3# by the following command:4#5# pip-compile dev.in6#7alabaster==0.7.168 # via9 # -r docs.txt10 # sphinx11babel==2.14.012 # via13 # -r docs.txt14 # sphinx15cachetools==5.3.37alabaster==1.0.08 # via sphinx9babel==2.16.010 # via sphinx11build==1.2.112 # via pip-tools13cachetools==5.5.014 # via tox17certifi==2024.2.218 # via19 # -r docs.txt20 # requests15certifi==2024.7.416 # via requests17cfgv==3.4.018 # via pre-commit19chardet==5.2.020 # via tox21charset-normalizer==3.3.222 # via requests23click==8.1.724 # via27 # -r docs.txt28 # requests25 # pip-compile-multi26 # pip-tools27colorama==0.4.628 # via tox29distlib==0.3.830 # via virtualenv31docutils==0.21.232 # via35 # -r docs.txt33 # sphinx34 # sphinx-tabs38filelock==3.13.435filelock==3.15.436 # via37 # tox38 # virtualenv42identify==2.5.3639identify==2.6.040 # via pre-commit44idna==3.745 # via46 # -r docs.txt47 # requests41idna==3.842 # via requests43imagesize==1.4.149 # via50 # -r docs.txt51 # sphinx44 # via sphinx45iniconfig==2.0.053 # via54 # -r tests.txt55 # -r typing.txt56 # pytest57jinja2==3.1.358 # via46 # via pytest47jinja2==3.1.448 # via sphinx59 # -r docs.txt60 # sphinx49markupsafe==2.1.562 # via63 # -r docs.txt64 # jinja250 # via jinja251mypy==1.11.166 # via -r typing.txt52 # via -r typing.in53mypy-extensions==1.0.054 # via mypy55nodeenv==1.9.156 # via69 # -r typing.txt70 # mypy71nodeenv==1.8.072 # via73 # -r typing.txt57 # pre-commit58 # pyright76packaging==24.059packaging==24.160 # via78 # -r docs.txt79 # -r tests.txt80 # -r typing.txt61 # build62 # pallets-sphinx-themes63 # pyproject-api64 # pytest65 # sphinx66 # tox67pallets-sphinx-themes==2.1.387 # via -r docs.txt88platformdirs==4.2.168 # via -r docs.in69pip-compile-multi==2.6.470 # via -r dev.in71pip-tools==7.4.172 # via pip-compile-multi73platformdirs==4.2.274 # via75 # tox76 # virtualenv77pluggy==1.5.078 # via94 # -r tests.txt95 # -r typing.txt79 # pytest80 # tox81pre-commit==3.8.082 # via -r dev.in100pygments==2.17.283pygments==2.18.084 # via102 # -r docs.txt85 # sphinx86 # sphinx-tabs105pyproject-api==1.6.187pyproject-api==1.7.188 # via tox107pyright==1.1.374108 # via -r typing.txt109pytest==8.3.289pyproject-hooks==1.1.090 # via111 # -r tests.txt112 # -r typing.txt113pyyaml==6.0.191 # build92 # pip-tools93pyright==1.1.37794 # via -r typing.in95pytest==8.3.296 # via -r tests.in97pyyaml==6.0.298 # via pre-commit115requests==2.31.0116 # via117 # -r docs.txt118 # sphinx99requests==2.32.3100 # via sphinx101snowballstemmer==2.2.0120 # via121 # -r docs.txt122 # sphinx102 # via sphinx103sphinx==8.0.2104 # via125 # -r docs.txt105 # -r docs.in106 # pallets-sphinx-themes107 # sphinx-issues108 # sphinx-tabs109 # sphinxcontrib-log-cabinet110sphinx-issues==4.1.0111 # via -r docs.in112sphinx-tabs==3.4.5130 # via -r docs.txt131sphinxcontrib-applehelp==1.0.8132 # via133 # -r docs.txt134 # sphinx135sphinxcontrib-devhelp==1.0.6136 # via137 # -r docs.txt138 # sphinx139sphinxcontrib-htmlhelp==2.0.5140 # via141 # -r docs.txt142 # sphinx113 # via -r docs.in114sphinxcontrib-applehelp==2.0.0115 # via sphinx116sphinxcontrib-devhelp==2.0.0117 # via sphinx118sphinxcontrib-htmlhelp==2.1.0119 # via sphinx120sphinxcontrib-jsmath==1.0.1144 # via145 # -r docs.txt146 # sphinx121 # via sphinx122sphinxcontrib-log-cabinet==1.0.1148 # via -r docs.txt149sphinxcontrib-qthelp==1.0.7150 # via151 # -r docs.txt152 # sphinx153sphinxcontrib-serializinghtml==1.1.10154 # via155 # -r docs.txt156 # sphinx157tox==4.15.1123 # via -r docs.in124sphinxcontrib-qthelp==2.0.0125 # via sphinx126sphinxcontrib-serializinghtml==2.0.0127 # via sphinx128toposort==1.10129 # via pip-compile-multi130tox==4.18.0131 # via -r dev.in159typing-extensions==4.11.0132typing-extensions==4.12.2133 # via mypy134urllib3==2.2.2135 # via requests136virtualenv==20.26.3137 # via161 # -r typing.txt162 # mypy163urllib3==2.2.1164 # via165 # -r docs.txt166 # requests167virtualenv==20.26.0168 # via138 # pre-commit139 # tox140wheel==0.44.0141 # via pip-tools142143# The following packages are considered to be unsafe in a requirements file:144# pip145# setuptools
modified:requirements/docs.txt+17 added-14 removed
2 unmodified lines
3# by the following command:4#5# pip-compile docs.in6#7alabaster==0.7.167alabaster==1.0.08 # via sphinx9babel==2.14.09babel==2.16.010 # via sphinx11certifi==2024.2.211certifi==2024.7.412 # via requests13charset-normalizer==3.3.214 # via requests15docutils==0.21.216 # via17 # sphinx18 # sphinx-tabs19idna==3.719idna==3.820 # via requests21imagesize==1.4.122 # via sphinx23jinja2==3.1.323jinja2==3.1.424 # via sphinx25markupsafe==2.1.526 # via jinja227packaging==24.027packaging==24.128 # via29 # pallets-sphinx-themes30 # sphinx31pallets-sphinx-themes==2.1.332 # via -r docs.in33pygments==2.17.233pygments==2.18.034 # via35 # sphinx36 # sphinx-tabs37requests==2.31.037requests==2.32.338 # via sphinx39snowballstemmer==2.2.040 # via sphinx41sphinx==8.0.242 # via43 # -r docs.in44 # pallets-sphinx-themes45 # sphinx-issues46 # sphinx-tabs47 # sphinxcontrib-log-cabinet48sphinx-issues==4.1.049 # via -r docs.in50sphinx-tabs==3.4.551 # via -r docs.in49sphinxcontrib-applehelp==1.0.852sphinxcontrib-applehelp==2.0.053 # via sphinx51sphinxcontrib-devhelp==1.0.654sphinxcontrib-devhelp==2.0.055 # via sphinx53sphinxcontrib-htmlhelp==2.0.556sphinxcontrib-htmlhelp==2.1.057 # via sphinx58sphinxcontrib-jsmath==1.0.159 # via sphinx60sphinxcontrib-log-cabinet==1.0.161 # via -r docs.in59sphinxcontrib-qthelp==1.0.762sphinxcontrib-qthelp==2.0.063 # via sphinx61sphinxcontrib-serializinghtml==1.1.1064sphinxcontrib-serializinghtml==2.0.065 # via sphinx63urllib3==2.2.166urllib3==2.2.267 # via requests
modified:requirements/tests.txt+1 added-1 removed
4 unmodified lines
5# pip-compile tests.in6#7iniconfig==2.0.08 # via pytest9packaging==24.09packaging==24.110 # via pytest11pluggy==1.5.012 # via pytest13pytest==8.3.2
1 unmodified line
added:requirements/tests37.txt+26 added
1#2# This file is autogenerated by pip-compile with Python 3.73# by the following command:4#5# pip-compile --output-file=tests37.txt tests.in6#7exceptiongroup==1.2.28 # via pytest9importlib-metadata==6.7.010 # via11 # pluggy12 # pytest13iniconfig==2.0.014 # via pytest15packaging==24.016 # via pytest17pluggy==1.2.018 # via pytest19pytest==7.4.420 # via -r tests.in21tomli==2.0.122 # via pytest23typing-extensions==4.7.124 # via importlib-metadata25zipp==3.15.026 # via importlib-metadata
modified:requirements/typing.txt+3 added-14 removed
2 unmodified lines
3# by the following command:4#5# pip-compile typing.in6#7iniconfig==2.0.08 # via pytest7mypy==1.11.18 # via -r typing.in9mypy-extensions==1.0.010 # via mypy13nodeenv==1.8.011nodeenv==1.9.112 # via pyright15packaging==24.016 # via pytest17pluggy==1.5.018 # via pytest19pyright==1.1.37413pyright==1.1.37714 # via -r typing.in21pytest==8.3.222 # via -r typing.in23typing-extensions==4.11.015typing-extensions==4.12.216 # via mypy2526# The following packages are considered to be unsafe in a requirements file:27# setuptools
modified:src/click/core.py+3 added-1 removed
2720 unmodified lines
2721 elif self.is_bool_flag and self.secondary_opts:2722 # For boolean flags that have distinct True/False opts,2723 # use the opt without prefix instead of the value.2724 default_string = _split_opt(2725 (self.opts if self.default else self.secondary_opts)[0]2725 (self.opts if default_value else self.secondary_opts)[0]2726 )[1]2727 elif self.is_bool_flag and not self.secondary_opts and not default_value:2728 default_string = ""2729 elif default_value == "":2730 default_string = '""'2731 else:2732 default_string = str(default_value)27332734 if default_string:
244 unmodified lines
modified:src/click/testing.py+2 added
9 unmodified lines
10import tempfile11import typing as t12from types import TracebackType1314from . import _compat15from . import formatting16from . import termui17from . import utils18from ._compat import _find_binary_reader
298 unmodified lines
317 termui.visible_prompt_func = visible_input318 termui.hidden_prompt_func = hidden_input319 termui._getchar = _getchar320 utils.should_strip_ansi = should_strip_ansi # type: ignore321 _compat.should_strip_ansi = should_strip_ansi322323 old_env = {}324 try:325 for key, value in env.items():
158 unmodified lines
modified:src/click/types.py+1 added-1 removed
891 unmodified lines
892 ctx,893 )894 if not self.dir_okay and stat.S_ISDIR(st.st_mode):895 self.fail(896 _("{name} '{filename}' is a directory.").format(896 _("{name} {filename!r} is a directory.").format(897 name=self.name.title(), filename=format_filename(value)898 ),899 param,900 ctx,
191 unmodified lines
modified:src/click/utils.py+3 added-3 removed
354 unmodified lines
355 return opener(encoding, errors)356357358def open_file(359 filename: str,359 filename: str | os.PathLike[str],360 mode: str = "r",361 encoding: str | None = None,362 errors: str | None = "strict",363 lazy: bool = False,
12 unmodified lines
376377 with open_file(filename) as f:378 ...379380 :param filename: The name of the file to open, or ``'-'`` for380 :param filename: The name or Path of the file to open, or ``'-'`` for381 ``stdin``/``stdout``.382 :param mode: The mode in which to open the file.383 :param encoding: The encoding to decode or encode a file opened in384 text mode.
27 unmodified lines
412 displayed by replacing any invalid bytes or surrogate escapes in the name413 with the replacement character ``�``.414415 Invalid bytes or surrogate escapes will raise an error when written to a416 stream with ``errors="strict". This will typically happen with ``stdout``416 stream with ``errors="strict"``. This will typically happen with ``stdout``417 when the locale is something like ``en_GB.UTF-8``.418419 Many scenarios *are* safe to write surrogates though, due to PEP 538 and420 PEP 540, including:
207 unmodified lines
modified:tests/test_defaults.py+25 added
57 unmodified lines
58 assert result.return_value == ((), (), ())5960 result = runner.invoke(cli, ["-y", "-n", "-f", "-v", "-q"], standalone_mode=False)61 assert result.return_value == ((True, False), (True,), (1, -1))626364def test_flag_default_map(runner):65 """test flag with default map"""6667 @click.group()68 def cli():69 pass7071 @cli.command()72 @click.option("--name/--no-name", is_flag=True, show_default=True, help="name flag")73 def foo(name):74 click.echo(name)7576 result = runner.invoke(cli, ["foo"])77 assert "False" in result.output7879 result = runner.invoke(cli, ["foo", "--help"])80 assert "default: no-name" in result.output8182 result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": True}})83 assert "True" in result.output8485 result = runner.invoke(cli, ["foo", "--help"], default_map={"foo": {"name": True}})86 assert "default: name" in result.output
modified:tests/test_options.py+8 added
784 unmodified lines
785 message = opt.get_help_record(ctx)[1]786 assert "[default: (unlimited)]" in message787788789def test_show_default_with_empty_string(runner):790 """When show_default is True and default is set to an empty string."""791 opt = click.Option(["--limit"], default="", show_default=True)792 ctx = click.Context(click.Command("cli"))793 message = opt.get_help_record(ctx)[1]794 assert '[default: ""]' in message795796797def test_do_not_show_no_default(runner):798 """When show_default is True and no default is set do not show None."""799 opt = click.Option(["--limit"], show_default=True)800 ctx = click.Context(click.Command("cli"))
128 unmodified lines
modified:tests/test_testing.py-2 removed
3 unmodified lines
45import pytest67import click8from click._compat import WIN8from click.testing import CliRunner91011def test_runner():
170 unmodified lines
182 result = runner.invoke(cli)183 assert result.exit_code == 1184185187@pytest.mark.skipif(WIN, reason="Test does not make sense on Windows.")186def test_with_color():187 @click.command()188 def cli():189 click.secho("hello world", fg="blue")
229 unmodified lines
modified:tests/test_types.py+12 added
1import os.path2import pathlib3import platform4import tempfile56import pytest7
224 unmodified lines
232233def test_file_error_surrogates():234 message = FileError(filename="\udcff").format_message()235 assert message == "Could not open file '�': unknown error"236237238@pytest.mark.skipif(239 platform.system() == "Windows", reason="Filepath syntax differences."240)241def test_invalid_path_with_esc_sequence():242 with pytest.raises(click.BadParameter) as exc_info:243 with tempfile.TemporaryDirectory(prefix="my\ndir") as tempdir:244 click.Path(dir_okay=False).convert(tempdir, None, None)245246 assert "my\\ndir" in exc_info.value.message
modified:.pre-commit-config.yaml+1 added-3 removed
1ci:2 autoupdate_schedule: monthly1repos:2 - repo: https://github.com/astral-sh/ruff-pre-commit5 rev: v0.5.63 rev: v0.6.24 hooks:5 - id: ruff6 - id: ruff-format7 - repo: https://github.com/pre-commit/pre-commit-hooks
7 unmodified lines
modified:CHANGES.rst+16 added
31 unmodified lines
32 suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed.33 :issue:`2322`343536Version 8.1.837-------------3839Unreleased4041- Fix an issue with type hints for ``click.open_file()``. :issue:`2717`42- Fix issue where error message for invalid ``click.Path`` displays on43 multiple lines. :issue:`2697`44- Fixed issue that prevented a default value of ``""`` from being displayed in45 the help for an option. :issue:`2500`46- The test runner handles stripping color consistently on Windows.47 :issue:`2705`48- Show correct value for flag default when using ``default_map``.49 :issue:`2632`505152Version 8.1.753-------------5455Released 2023-08-17
1098 unmodified lines
modified:CONTRIBUTING.rst+1 added-1 removed
136 unmodified lines
137138 .. code-block:: text139140 $ git fetch origin141 $ git checkout -b your-branch-name origin/8.0.x141 $ git checkout -b your-branch-name origin/8.1.x142143 If you're submitting a feature addition or change, branch off of the144 "main" branch.145
71 unmodified lines
modified:pyproject.toml+5 added-1 removed
89 unmodified lines
90 "I", # isort91 "UP", # pyupgrade92 "W", # pycodestyle warning93]94ignore-init-module-imports = true9495[tool.ruff.lint.isort]96force-single-line = true97order-by-type = false9899[tool.gha-update]100tag-only = [101 "slsa-framework/slsa-github-generator",102]
modified:tox.ini+29 added-9 removed
13 unmodified lines
14use_frozen_constraints = true15deps = -r requirements/tests.txt16commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}1718[testenv:py37,py3.7]19deps = -r requirements/tests37.txt2021[testenv:style]22deps = pre-commit23skip_install = true24commands = pre-commit run --all-files
8 unmodified lines
33[testenv:docs]34deps = -r requirements/docs.txt35commands = sphinx-build -E -W -b dirhtml docs docs/_build/dirhtml3637[testenv:update-actions]38labels = update39deps = gha-update40commands = gha-update4142[testenv:update-pre_commit]43labels = update44deps = pre-commit45skip_install = true46commands = pre-commit autoupdate -j44748[testenv:update-requirements]35deps =36 pip-tools37 pre-commit49labels = update50deps = pip-tools51skip_install = true52change_dir = requirements53commands =41 pre-commit autoupdate -j442 pip-compile -U build.in43 pip-compile -U docs.in44 pip-compile -U tests.in45 pip-compile -U typing.in46 pip-compile -U dev.in54 pip-compile build.in -q {posargs:-U}55 pip-compile docs.in -q {posargs:-U}56 pip-compile tests.in -q {posargs:-U}57 pip-compile typing.in -q {posargs:-U}58 pip-compile dev.in -q {posargs:-U}5960[testenv:update-requirements37]61base_python = 3.762labels = update63deps = pip-tools64skip_install = true65change_dir = requirements66commands = pip-compile tests.in -q -o tests37.txt {posargs:-U}