Merge remote-tracking branch 'origin/8.0.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 ff72d7d, 76cc18d · Browse files · 10 files·+87 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+87 added−17 removed
- tests:+38 added−0 removed
- other:+49 added−17 removed
Provenance
- Commit
ce152bd- Tree
7235fa3- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
ff72d7d- Parent 2
76cc18d
10 files changed+87 added−17 removed
modified:docs/api.rst+2 added
139 unmodified lines140 .. autoclass:: IntRange141 142 .. autoclass:: FloatRange143 144+.. autoclass:: DateTime145+146 .. autoclass:: Tuple147 148 .. autoclass:: ParamType149 :members:62 unmodified linesmodified:docs/utils.rst+7 added-2 removed
337 unmodified lines338 339 Showing Progress Bars340 ---------------------341 342-.. versionadded:: 2.0343-342 Sometimes, you have command line scripts that need to process a lot of data,343 but you want to quickly show the user some progress about how long that344 will take. Click supports simple progress bar rendering for that through345 the :func:`progressbar` function.346 347+.. note::348+349+ If you find that you have requirements beyond what Click's progress350+ bar supports, try using `tqdm`_.351+352+ .. _tqdm: https://tqdm.github.io/353+354 The basic usage is very simple: the idea is that you have an iterable that355 you want to operate on. For each item in the iterable it might take some356 time to do processing. So say you have a loop like this::357 51 unmodified linesmodified:examples/completion/completion.py+4 added-1 removed
36 unmodified lines37 # You can generate completions with help strings by returning a list38 # of CompletionItem. You can match on whatever you want, including39 # the help.40 items = [("bob", "butcher"), ("alice", "baker"), ("jerry", "candlestick maker")]41+ out = []42 43 for value, help in items:44 if incomplete in value or incomplete in help:44- yield CompletionItem(value, help=help)45+ out.append(CompletionItem(value, help=help))46 47+ return out48 49+50 @group.command(help="Choose a user")51 @click.argument("user", shell_complete=list_users)52 def select_user(user):53 click.echo(f"Chosen user is {user}")3 unmodified linesmodified:examples/completion/README+3 added-3 removed
9 unmodified lines10 For Bash:11 12 .. code-block:: bash13 14- eval "$(_COMPLETION_COMPLETE=source_bash completion)"14+ eval "$(_COMPLETION_COMPLETE=bash_source completion)"15 16 For Zsh:17 18 .. code-block:: zsh19 20- eval "$(_COMPLETION_COMPLETE=source_zsh completion)"20+ eval "$(_COMPLETION_COMPLETE=zsh_source completion)"21 22 For Fish:23 24 .. code-block:: fish25 26- eval (env _COMPLETION_COMPLETE=source_fish completion)26+ eval (env _COMPLETION_COMPLETE=fish_source completion)27 28 Now press tab (maybe twice) after typing something to see completions.modified:src/click/core.py+7 added-6 removed
2195 unmodified lines2196 def get_default(2197 self, ctx: Context, call: bool = True2198 ) -> t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]:2199 """Get the default for the parameter. Tries2200- :meth:`Context.lookup_value` first, then the local default.2200+ :meth:`Context.lookup_default` first, then the local default.2201 2202 :param ctx: Current context.2203 :param call: If the default is a callable, call it. Disable to2204 return the callable instead.255 unmodified lines2460 2461 def __init__(2462 self,2463 param_decls: t.Optional[t.Sequence[str]] = None,2464- show_default: bool = False,2464+ show_default: t.Union[bool, str] = False,2465 prompt: t.Union[bool, str] = False,2466 confirmation_prompt: t.Union[bool, str] = False,2467 prompt_required: bool = True,2468 hide_input: bool = False,58 unmodified lines2527 # default.2528 self.type = types.convert_type(None, flag_value)2529 2530 self.is_flag: bool = is_flag2531- self.is_bool_flag = isinstance(self.type, types.BoolParamType)2531+ self.is_bool_flag = is_flag and isinstance(self.type, types.BoolParamType)2532 self.flag_value: t.Any = flag_value2533 2534 # Counting2535 self.count = count53 unmodified lines2589 2590 for decl in decls:2591 if decl.isidentifier():2592 if name is not None:2593- raise TypeError("Name defined twice")2593+ raise TypeError(f"Name '{name}' defined twice")2594 name = decl2595 else:2596 split_char = ";" if decl[:1] == "/" else "/"2597 if split_char in decl:149 unmodified lines2747 )[1]2748 else:2749 default_string = str(default_value)2750 2751+ if default_string:2751- extra.append(_("default: {default}").format(default=default_string))2752+ extra.append(_("default: {default}").format(default=default_string))2753 2754 if isinstance(self.type, types._NumberRangeBase):2755 range_str = self.type._describe_range()2756 3 unmodified lines2760 if self.required:2761 extra.append(_("required"))2762 2763 if extra:2763- extra_str = ";".join(extra)2764+ extra_str = "; ".join(extra)2765 help = f"{help} [{extra_str}]" if help else f"[{extra_str}]"2766 2767 return ("; " if any_prefix_is_slash else " / ").join(rv), help2768 190 unmodified linesmodified:src/click/shell_completion.py+10 added-3 removed
300 unmodified lines301 302 def _check_version(self) -> None:303 import subprocess304 305- output = subprocess.run(["bash", "--version"], stdout=subprocess.PIPE)306- match = re.search(r"version (\d)\.(\d)\.\d", output.stdout.decode())305+ output = subprocess.run(306+ ["bash", "-c", "echo ${BASH_VERSION}"], stdout=subprocess.PIPE307+ )308+ match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode())309 310 if match is not None:311 major, minor = match.groups()312 136 unmodified lines449 450 451 def _start_of_option(value: str) -> bool:452 """Check if the value looks like the start of an option."""451- return not value[0].isalnum() if value else False453+ if not value:454+ return False455 456+ c = value[0]457+ # Allow "/" since that starts a path.458+ return not c.isalnum() and c != "/"459 460+461 def _is_incomplete_option(args: t.List[str], param: Parameter) -> bool:462 """Determine if the given parameter is an option that needs a value.463 464 :param args: List of complete args before the incomplete value.117 unmodified linesmodified:tests/test_options.py+30 added
2 unmodified lines3 4 import pytest5 6 import click7+from click import Option8 9 10 def test_prefixes(runner):11 @click.command()715 unmodified lines727 message = opt.get_help_record(ctx)[1]728 assert "[default: None]" not in message729 730 731+def test_do_not_show_default_empty_multiple():732+ """When show_default is True and multiple=True is set, it should not733+ print empty default value in --help output.734+ """735+ opt = click.Option(["-a"], multiple=True, help="values", show_default=True)736+ ctx = click.Context(click.Command("cli"))737+ message = opt.get_help_record(ctx)[1]738+ assert message == "values"739+740+741 @pytest.mark.parametrize(742 ("args", "expect"),743 [744 (None, (None, None, ())),28 unmodified lines773 param = click.Option(["-a", "x"], default=True, flag_value=4)774 assert param.type is click.INT775 param = click.Option(["-b", "x"], flag_value=8)776 assert param.type is click.INT777+778+779+@pytest.mark.parametrize(780+ ("option", "expected"),781+ [782+ # Not boolean flags783+ pytest.param(Option(["-a"], type=int), False, id="int option"),784+ pytest.param(Option(["-a"], type=bool), False, id="bool non-flag [None]"),785+ pytest.param(Option(["-a"], default=True), False, id="bool non-flag [True]"),786+ pytest.param(Option(["-a"], default=False), False, id="bool non-flag [False]"),787+ pytest.param(Option(["-a"], flag_value=1), False, id="non-bool flag_value"),788+ # Boolean flags789+ pytest.param(Option(["-a"], is_flag=True), True, id="is_flag=True"),790+ pytest.param(Option(["-a/-A"]), True, id="secondary option [implicit flag]"),791+ pytest.param(Option(["-a"], flag_value=True), True, id="bool flag_value"),792+ ],793+)794+def test_is_bool_flag_is_correctly_set(option, expected):795+ assert option.is_bool_flag is expectedmodified:tests/test_shell_completion.py+8 added
123 unmodified lines124 assert c.value == "ab"125 assert c.type == expect126 127 128+def test_absolute_path():129+ cli = Command("cli", params=[Option(["-f"], type=Path())])130+ out = _get_completions(cli, ["-f"], "/ab")131+ assert len(out) == 1132+ c = out[0]133+ assert c.value == "/ab"134+135+136 def test_option_flag():137 cli = Command(138 "cli",139 add_help_option=False,183 unmodified linesmodified:CHANGES.rst+8 added
9 unmodified lines10 -------------11 12 Unreleased13 14+- ``is_bool_flag`` is not set to ``True`` if ``is_flag`` is ``False``.15+ :issue:`1925`16+- Bash version detection is locale independent. :issue:`1940`17+- Empty ``default`` value is not shown for ``multiple=True``.18+ :issue:`1969`19+- Fix shell completion for arguments that start with a forward slash20+ such as absolute file paths. :issue:`1929`21 22+23 Version 8.0.124 -------------25 26 Released 2021-05-19887 unmodified linesmodified:CONTRIBUTING.rst+8 added-2 removed
90 unmodified lines91 default Pallets remote is "origin".92 93 .. code-block:: text94 95- git remote add fork https://github.com/{username}/click95+ $ git remote add fork https://github.com/{username}/click96 97 - Create a virtualenv.98 99 .. code-block:: text6 unmodified lines106 .. code-block:: text107 108 > env\Scripts\activate109 110+- Upgrade pip and setuptools.111+112+ .. code-block:: text113+114+ $ python -m pip install --upgrade pip setuptools115+116 - Install the development dependencies, then install Click in117 editable mode.118 119 .. code-block:: text23 unmodified lines143 144 .. code-block:: text145 146 $ git fetch origin141- $ git checkout -b your-branch-name origin/7.x147+ $ git checkout -b your-branch-name origin/8.0.x148 149 If you're submitting a feature addition or change, branch off of the150 "main" branch.151 71 unmodified lines