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
Provenance
- Commit
99015e1- Tree
45ee71d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
e16088a- Parent 2
aca1a0c
24 files changed+247 added−185 removed
modified:.github/workflows/publish.yaml+1 added-1 removed
21 unmodified lines2223242526262728293043 unmodified lines21 unmodified lines # Generate hashes used for provenance. - name: generate hash id: hash run: cd dist && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT - uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4.3.6 with: path: ./dist provenance: needs: [build]43 unmodified linesdeleted:.github/dependabot.yml-18 removed
123456789101112131415161718version: 2updates: - package-ecosystem: github-actions directory: / schedule: interval: monthly groups: github-actions: patterns: - '*' - package-ecosystem: pip directory: /requirements/ schedule: interval: monthly groups: python-requirements: patterns: - '*'modified:docs/advanced.rst+1 added
440 unmodified lines441 442 def __enter__(self):443 path = os.path.join(self.home, "repo.db")444 self.db = open_database(path)445+ return self446 447 def __exit__(self, exc_type, exc_value, tb):448 self.db.close()449 47 unmodified linesmodified:docs/conf.py+2 added-2 removed
21 unmodified lines22 autodoc_member_order = "bysource"23 autodoc_typehints = "description"24 autodoc_preserve_defaults = True25 extlinks = {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 }29 intersphinx_mapping = {30 "python": ("https://docs.python.org/3/", None),31 }24 unmodified linesmodified:docs/shell-completion.rst+14 added-10 removed
26 unmodified lines27 through an entry point, not through the ``python`` command. See28 :doc:`entry-points`. Once the executable is installed, calling it with29 a special environment variable will put Click in completion mode.30 31-In order for completion to be used, the user needs to register a special32-function with their shell. The script is different for every shell, and33-Click will output it when called with ``_{PROG_NAME}_COMPLETE`` set to34-``{shell}_source``. ``{PROG_NAME}`` is the executable name in uppercase35-with dashes replaced by underscores. The built-in shells are ``bash``,36-``zsh``, and ``fish``.31+To enable shell completion, the user needs to register a special32+function with their shell. The exact script varies depending on the33+shell you are using. Click will output it when called with34+``_{FOO_BAR}_COMPLETE`` set to ``{shell}_source``. ``{FOO_BAR}`` is35+the executable name in uppercase with dashes replaced by underscores.36+It is conventional but not strictly required for environment variable37+names to be in upper case. This convention helps distinguish environment38+variables from regular shell variables and commands, making scripts39+and configuration files more readable and easier to maintain. The40+built-in shells are ``bash``, ``zsh``, and ``fish``.41 42 Provide your users with the following instructions customized to your43 program name. This uses ``foo-bar`` as an example.44 152 unmodified lines197 require implementing some smaller parts.198 199 First, you'll need to figure out how your shell's completion system200 works and write a script to integrate it with Click. It must invoke your197-program with the environment variable ``_{PROG_NAME}_COMPLETE`` set to201+program with the environment variable ``_{FOO_BAR}_COMPLETE`` set to202 ``{shell}_complete`` and pass the complete args and incomplete value.203 How it passes those values, and the format of the completion response204 from Click is up to you.205 4 unmodified lines210 - ``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.215 216 The example code is for a made up shell "My Shell" or "mysh" for short.217 218 .. code-block:: python2 unmodified lines221 from click.shell_completion import ShellComplete222 223 _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 """230 231 @add_completion_class232 class MyshComplete(ShellComplete):59 unmodified linesmodified:requirements/build.txt+2 added-2 removed
4 unmodified lines5 # pip-compile build.in6 #7 build==1.2.18 # via -r build.in9-packaging==24.09+packaging==24.110 # via build11-pyproject-hooks==1.0.011+pyproject-hooks==1.1.012 # via buildmodified:requirements/dev.txt+74 added-102 removed
2 unmodified lines3 # by the following command:4 #5 # pip-compile dev.in6 #7-alabaster==0.7.168- # via9- # -r docs.txt10- # sphinx11-babel==2.14.012- # via13- # -r docs.txt14- # sphinx15-cachetools==5.3.37+alabaster==1.0.08+ # via sphinx9+babel==2.16.010+ # via sphinx11+build==1.2.112+ # via pip-tools13+cachetools==5.5.014 # via tox17-certifi==2024.2.218- # via19- # -r docs.txt20- # requests15+certifi==2024.7.416+ # via requests17 cfgv==3.4.018 # via pre-commit19 chardet==5.2.020 # via tox21 charset-normalizer==3.3.222+ # via requests23+click==8.1.724 # via27- # -r docs.txt28- # requests25+ # pip-compile-multi26+ # pip-tools27 colorama==0.4.628 # via tox29 distlib==0.3.830 # via virtualenv31 docutils==0.21.232 # via35- # -r docs.txt33 # sphinx34 # sphinx-tabs38-filelock==3.13.435+filelock==3.15.436 # via37 # tox38 # virtualenv42-identify==2.5.3639+identify==2.6.040 # via pre-commit44-idna==3.745- # via46- # -r docs.txt47- # requests41+idna==3.842+ # via requests43 imagesize==1.4.149- # via50- # -r docs.txt51- # sphinx44+ # via sphinx45 iniconfig==2.0.053- # via54- # -r tests.txt55- # -r typing.txt56- # pytest57-jinja2==3.1.358- # via46+ # via pytest47+jinja2==3.1.448+ # via sphinx59- # -r docs.txt60- # sphinx49 markupsafe==2.1.562- # via63- # -r docs.txt64- # jinja250+ # via jinja251 mypy==1.11.166- # via -r typing.txt52+ # via -r typing.in53 mypy-extensions==1.0.054+ # via mypy55+nodeenv==1.9.156 # via69- # -r typing.txt70- # mypy71-nodeenv==1.8.072- # via73- # -r typing.txt57 # pre-commit58 # pyright76-packaging==24.059+packaging==24.160 # via78- # -r docs.txt79- # -r tests.txt80- # -r typing.txt61+ # build62 # pallets-sphinx-themes63 # pyproject-api64 # pytest65 # sphinx66 # tox67 pallets-sphinx-themes==2.1.387- # via -r docs.txt88-platformdirs==4.2.168+ # via -r docs.in69+pip-compile-multi==2.6.470+ # via -r dev.in71+pip-tools==7.4.172+ # via pip-compile-multi73+platformdirs==4.2.274 # via75 # tox76 # virtualenv77 pluggy==1.5.078 # via94- # -r tests.txt95- # -r typing.txt79 # pytest80 # tox81 pre-commit==3.8.082 # via -r dev.in100-pygments==2.17.283+pygments==2.18.084 # via102- # -r docs.txt85 # sphinx86 # sphinx-tabs105-pyproject-api==1.6.187+pyproject-api==1.7.188 # via tox107-pyright==1.1.374108- # via -r typing.txt109-pytest==8.3.289+pyproject-hooks==1.1.090 # via111- # -r tests.txt112- # -r typing.txt113-pyyaml==6.0.191+ # build92+ # pip-tools93+pyright==1.1.37794+ # via -r typing.in95+pytest==8.3.296+ # via -r tests.in97+pyyaml==6.0.298 # via pre-commit115-requests==2.31.0116- # via117- # -r docs.txt118- # sphinx99+requests==2.32.3100+ # via sphinx101 snowballstemmer==2.2.0120- # via121- # -r docs.txt122- # sphinx102+ # via sphinx103 sphinx==8.0.2104 # via125- # -r docs.txt105+ # -r docs.in106 # pallets-sphinx-themes107+ # sphinx-issues108 # sphinx-tabs109 # sphinxcontrib-log-cabinet110+sphinx-issues==4.1.0111+ # via -r docs.in112 sphinx-tabs==3.4.5130- # via -r docs.txt131-sphinxcontrib-applehelp==1.0.8132- # via133- # -r docs.txt134- # sphinx135-sphinxcontrib-devhelp==1.0.6136- # via137- # -r docs.txt138- # sphinx139-sphinxcontrib-htmlhelp==2.0.5140- # via141- # -r docs.txt142- # sphinx113+ # via -r docs.in114+sphinxcontrib-applehelp==2.0.0115+ # via sphinx116+sphinxcontrib-devhelp==2.0.0117+ # via sphinx118+sphinxcontrib-htmlhelp==2.1.0119+ # via sphinx120 sphinxcontrib-jsmath==1.0.1144- # via145- # -r docs.txt146- # sphinx121+ # via sphinx122 sphinxcontrib-log-cabinet==1.0.1148- # via -r docs.txt149-sphinxcontrib-qthelp==1.0.7150- # via151- # -r docs.txt152- # sphinx153-sphinxcontrib-serializinghtml==1.1.10154- # via155- # -r docs.txt156- # sphinx157-tox==4.15.1123+ # via -r docs.in124+sphinxcontrib-qthelp==2.0.0125+ # via sphinx126+sphinxcontrib-serializinghtml==2.0.0127+ # via sphinx128+toposort==1.10129+ # via pip-compile-multi130+tox==4.18.0131 # via -r dev.in159-typing-extensions==4.11.0132+typing-extensions==4.12.2133+ # via mypy134+urllib3==2.2.2135+ # via requests136+virtualenv==20.26.3137 # via161- # -r typing.txt162- # mypy163-urllib3==2.2.1164- # via165- # -r docs.txt166- # requests167-virtualenv==20.26.0168- # via138 # pre-commit139 # tox140+wheel==0.44.0141+ # via pip-tools142 143 # The following packages are considered to be unsafe in a requirements file:144+# pip145 # setuptoolsmodified:requirements/docs.txt+17 added-14 removed
2 unmodified lines3 # by the following command:4 #5 # pip-compile docs.in6 #7-alabaster==0.7.167+alabaster==1.0.08 # via sphinx9-babel==2.14.09+babel==2.16.010 # via sphinx11-certifi==2024.2.211+certifi==2024.7.412 # via requests13 charset-normalizer==3.3.214 # via requests15 docutils==0.21.216 # via17 # sphinx18 # sphinx-tabs19-idna==3.719+idna==3.820 # via requests21 imagesize==1.4.122 # via sphinx23-jinja2==3.1.323+jinja2==3.1.424 # via sphinx25 markupsafe==2.1.526 # via jinja227-packaging==24.027+packaging==24.128 # via29 # pallets-sphinx-themes30 # sphinx31 pallets-sphinx-themes==2.1.332 # via -r docs.in33-pygments==2.17.233+pygments==2.18.034 # via35 # sphinx36 # sphinx-tabs37-requests==2.31.037+requests==2.32.338 # via sphinx39 snowballstemmer==2.2.040 # via sphinx41 sphinx==8.0.242 # via43 # -r docs.in44 # pallets-sphinx-themes45+ # sphinx-issues46 # sphinx-tabs47 # sphinxcontrib-log-cabinet48+sphinx-issues==4.1.049+ # via -r docs.in50 sphinx-tabs==3.4.551 # via -r docs.in49-sphinxcontrib-applehelp==1.0.852+sphinxcontrib-applehelp==2.0.053 # via sphinx51-sphinxcontrib-devhelp==1.0.654+sphinxcontrib-devhelp==2.0.055 # via sphinx53-sphinxcontrib-htmlhelp==2.0.556+sphinxcontrib-htmlhelp==2.1.057 # via sphinx58 sphinxcontrib-jsmath==1.0.159 # via sphinx60 sphinxcontrib-log-cabinet==1.0.161 # via -r docs.in59-sphinxcontrib-qthelp==1.0.762+sphinxcontrib-qthelp==2.0.063 # via sphinx61-sphinxcontrib-serializinghtml==1.1.1064+sphinxcontrib-serializinghtml==2.0.065 # via sphinx63-urllib3==2.2.166+urllib3==2.2.267 # via requestsmodified:requirements/tests.txt+1 added-1 removed
4 unmodified lines5 # pip-compile tests.in6 #7 iniconfig==2.0.08 # via pytest9-packaging==24.09+packaging==24.110 # via pytest11 pluggy==1.5.012 # via pytest13 pytest==8.3.21 unmodified lineadded: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+#7+exceptiongroup==1.2.28+ # via pytest9+importlib-metadata==6.7.010+ # via11+ # pluggy12+ # pytest13+iniconfig==2.0.014+ # via pytest15+packaging==24.016+ # via pytest17+pluggy==1.2.018+ # via pytest19+pytest==7.4.420+ # via -r tests.in21+tomli==2.0.122+ # via pytest23+typing-extensions==4.7.124+ # via importlib-metadata25+zipp==3.15.026+ # via importlib-metadatamodified:requirements/typing.txt+3 added-14 removed
2 unmodified lines3 # by the following command:4 #5 # pip-compile typing.in6 #7-iniconfig==2.0.08- # via pytest7 mypy==1.11.18 # via -r typing.in9 mypy-extensions==1.0.010 # via mypy13-nodeenv==1.8.011+nodeenv==1.9.112 # via pyright15-packaging==24.016- # via pytest17-pluggy==1.5.018- # via pytest19-pyright==1.1.37413+pyright==1.1.37714 # via -r typing.in21-pytest==8.3.222- # via -r typing.in23-typing-extensions==4.11.015+typing-extensions==4.12.216 # via mypy25-26-# The following packages are considered to be unsafe in a requirements file:27-# setuptoolsmodified:src/click/core.py+3 added-1 removed
2720 unmodified lines2721 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)2733 2734 if default_string:244 unmodified linesmodified:src/click/testing.py+2 added
9 unmodified lines10 import tempfile11 import typing as t12 from types import TracebackType13 14+from . import _compat15 from . import formatting16 from . import termui17 from . import utils18 from ._compat import _find_binary_reader298 unmodified lines317 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_ansi322 323 old_env = {}324 try:325 for key, value in env.items():158 unmodified linesmodified:src/click/types.py+1 added-1 removed
891 unmodified lines892 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 linesmodified:src/click/utils.py+3 added-3 removed
354 unmodified lines355 return opener(encoding, errors)356 357 358 def 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 lines376 377 with open_file(filename) as f:378 ...379 380- :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 lines412 displayed by replacing any invalid bytes or surrogate escapes in the name413 with the replacement character ``�``.414 415 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``.418 419 Many scenarios *are* safe to write surrogates though, due to PEP 538 and420 PEP 540, including:207 unmodified linesmodified:tests/test_defaults.py+25 added
57 unmodified lines58 assert result.return_value == ((), (), ())59 60 result = runner.invoke(cli, ["-y", "-n", "-f", "-v", "-q"], standalone_mode=False)61 assert result.return_value == ((True, False), (True,), (1, -1))62+63+64+def test_flag_default_map(runner):65+ """test flag with default map"""66+67+ @click.group()68+ def cli():69+ pass70+71+ @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)75+76+ result = runner.invoke(cli, ["foo"])77+ assert "False" in result.output78+79+ result = runner.invoke(cli, ["foo", "--help"])80+ assert "default: no-name" in result.output81+82+ result = runner.invoke(cli, ["foo"], default_map={"foo": {"name": True}})83+ assert "True" in result.output84+85+ result = runner.invoke(cli, ["foo", "--help"], default_map={"foo": {"name": True}})86+ assert "default: name" in result.outputmodified:tests/test_options.py+8 added
784 unmodified lines785 message = opt.get_help_record(ctx)[1]786 assert "[default: (unlimited)]" in message787 788 789+def 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 message795+796+797 def 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 linesmodified:tests/test_testing.py-2 removed
3 unmodified lines4 5 import pytest6 7 import click8-from click._compat import WIN8 from click.testing import CliRunner9 10 11 def test_runner():170 unmodified lines182 result = runner.invoke(cli)183 assert result.exit_code == 1184 185 187-@pytest.mark.skipif(WIN, reason="Test does not make sense on Windows.")186 def test_with_color():187 @click.command()188 def cli():189 click.secho("hello world", fg="blue")229 unmodified linesmodified:tests/test_types.py+12 added
1 import os.path2 import pathlib3+import platform4 import tempfile5 6 import pytest7 224 unmodified lines232 233 def test_file_error_surrogates():234 message = FileError(filename="\udcff").format_message()235 assert message == "Could not open file '�': unknown error"236+237+238+@pytest.mark.skipif(239+ platform.system() == "Windows", reason="Filepath syntax differences."240+)241+def 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)245+246+ assert "my\\ndir" in exc_info.value.messagemodified:.pre-commit-config.yaml+1 added-3 removed
1-ci:2- autoupdate_schedule: monthly1 repos: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-hooks7 unmodified linesmodified:CHANGES.rst+16 added
31 unmodified lines32 suffixes ``_command``, ``_cmd``, ``_group``, and ``_grp`` are removed.33 :issue:`2322`34 35 36+Version 8.1.837+-------------38+39+Unreleased40+41+- 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`50+51+52 Version 8.1.753 -------------54 55 Released 2023-08-171098 unmodified linesmodified:CONTRIBUTING.rst+1 added-1 removed
136 unmodified lines137 138 .. code-block:: text139 140 $ git fetch origin141- $ git checkout -b your-branch-name origin/8.0.x141+ $ git checkout -b your-branch-name origin/8.1.x142 143 If you're submitting a feature addition or change, branch off of the144 "main" branch.145 71 unmodified linesmodified:pyproject.toml+5 added-1 removed
89 unmodified lines90 "I", # isort91 "UP", # pyupgrade92 "W", # pycodestyle warning93 ]94-ignore-init-module-imports = true94 95 [tool.ruff.lint.isort]96 force-single-line = true97 order-by-type = false98+99+[tool.gha-update]100+tag-only = [101+ "slsa-framework/slsa-github-generator",102+]modified:tox.ini+29 added-9 removed
13 unmodified lines14 use_frozen_constraints = true15 deps = -r requirements/tests.txt16 commands = pytest -v --tb=short --basetemp={envtmpdir} {posargs}17 18+[testenv:py37,py3.7]19+deps = -r requirements/tests37.txt20+21 [testenv:style]22 deps = pre-commit23 skip_install = true24 commands = pre-commit run --all-files8 unmodified lines33 [testenv:docs]34 deps = -r requirements/docs.txt35 commands = sphinx-build -E -W -b dirhtml docs docs/_build/dirhtml36 37+[testenv:update-actions]38+labels = update39+deps = gha-update40+commands = gha-update41+42+[testenv:update-pre_commit]43+labels = update44+deps = pre-commit45+skip_install = true46+commands = pre-commit autoupdate -j447+48 [testenv:update-requirements]35-deps =36- pip-tools37- pre-commit49+labels = update50+deps = pip-tools51 skip_install = true52 change_dir = requirements53 commands =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}59+60+[testenv:update-requirements37]61+base_python = 3.762+labels = update63+deps = pip-tools64+skip_install = true65+change_dir = requirements66+commands = pip-compile tests.in -q -o tests37.txt {posargs:-U}