Skip to content
Myr

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

10 files+87 added−17 removed

modified:docs/api.rst+2 added
139 unmodified lines
140.. autoclass:: IntRange141142.. autoclass:: FloatRange143144.. autoclass:: DateTime145146.. autoclass:: Tuple147148.. autoclass:: ParamType149 :members:
62 unmodified lines
modified:docs/utils.rst+7 added-2 removed
337 unmodified lines
338339Showing Progress Bars340---------------------341342.. versionadded:: 2.0343342Sometimes, you have command line scripts that need to process a lot of data,343but you want to quickly show the user some progress about how long that344will take. Click supports simple progress bar rendering for that through345the :func:`progressbar` function.346347.. note::348349 If you find that you have requirements beyond what Click's progress350 bar supports, try using `tqdm`_.351352 .. _tqdm: https://tqdm.github.io/353354The basic usage is very simple: the idea is that you have an iterable that355you want to operate on. For each item in the iterable it might take some356time to do processing. So say you have a loop like this::357
51 unmodified lines
modified:examples/completion/completion.py+4 added-1 removed
36 unmodified lines
37 # 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 = []4243 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))4647 return out484950@group.command(help="Choose a user")51@click.argument("user", shell_complete=list_users)52def select_user(user):53 click.echo(f"Chosen user is {user}")
3 unmodified lines
modified:examples/completion/README+3 added-3 removed
9 unmodified lines
10For Bash:1112.. code-block:: bash1314 eval "$(_COMPLETION_COMPLETE=source_bash completion)"14 eval "$(_COMPLETION_COMPLETE=bash_source completion)"1516For Zsh:1718.. code-block:: zsh1920 eval "$(_COMPLETION_COMPLETE=source_zsh completion)"20 eval "$(_COMPLETION_COMPLETE=zsh_source completion)"2122For Fish:2324.. code-block:: fish2526 eval (env _COMPLETION_COMPLETE=source_fish completion)26 eval (env _COMPLETION_COMPLETE=fish_source completion)2728Now press tab (maybe twice) after typing something to see completions.
modified:src/click/core.py+7 added-6 removed
2195 unmodified lines
2196 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.22012202 :param ctx: Current context.2203 :param call: If the default is a callable, call it. Disable to2204 return the callable instead.
255 unmodified lines
24602461 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 lines
2527 # default.2528 self.type = types.convert_type(None, flag_value)25292530 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_value25332534 # Counting2535 self.count = count
53 unmodified lines
25892590 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 lines
2747 )[1]2748 else:2749 default_string = str(default_value)27502751 if default_string:2751 extra.append(_("default: {default}").format(default=default_string))2752 extra.append(_("default: {default}").format(default=default_string))27532754 if isinstance(self.type, types._NumberRangeBase):2755 range_str = self.type._describe_range()2756
3 unmodified lines
2760 if self.required:2761 extra.append(_("required"))27622763 if extra:2763 extra_str = ";".join(extra)2764 extra_str = "; ".join(extra)2765 help = f"{help} [{extra_str}]" if help else f"[{extra_str}]"27662767 return ("; " if any_prefix_is_slash else " / ").join(rv), help2768
190 unmodified lines
modified:src/click/shell_completion.py+10 added-3 removed
300 unmodified lines
301302 def _check_version(self) -> None:303 import subprocess304305 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())309310 if match is not None:311 major, minor = match.groups()312
136 unmodified lines
449450451def _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 False455456 c = value[0]457 # Allow "/" since that starts a path.458 return not c.isalnum() and c != "/"459460461def _is_incomplete_option(args: t.List[str], param: Parameter) -> bool:462 """Determine if the given parameter is an option that needs a value.463464 :param args: List of complete args before the incomplete value.
117 unmodified lines
modified:tests/test_options.py+30 added
2 unmodified lines
34import pytest56import click7from click import Option8910def test_prefixes(runner):11 @click.command()
715 unmodified lines
727 message = opt.get_help_record(ctx)[1]728 assert "[default: None]" not in message729730731def 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"739740741@pytest.mark.parametrize(742 ("args", "expect"),743 [744 (None, (None, None, ())),
28 unmodified lines
773 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.INT777778779@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)794def test_is_bool_flag_is_correctly_set(option, expected):795 assert option.is_bool_flag is expected
modified:tests/test_shell_completion.py+8 added
123 unmodified lines
124 assert c.value == "ab"125 assert c.type == expect126127128def 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"134135136def test_option_flag():137 cli = Command(138 "cli",139 add_help_option=False,
183 unmodified lines
modified:CHANGES.rst+8 added
9 unmodified lines
10-------------1112Unreleased1314- ``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`212223Version 8.0.124-------------2526Released 2021-05-19
887 unmodified lines
modified:CONTRIBUTING.rst+8 added-2 removed
90 unmodified lines
91 default Pallets remote is "origin".9293 .. code-block:: text9495 git remote add fork https://github.com/{username}/click95 $ git remote add fork https://github.com/{username}/click9697- Create a virtualenv.9899 .. code-block:: text
6 unmodified lines
106 .. code-block:: text107108 > env\Scripts\activate109110- Upgrade pip and setuptools.111112 .. code-block:: text113114 $ python -m pip install --upgrade pip setuptools115116- Install the development dependencies, then install Click in117 editable mode.118119 .. code-block:: text
23 unmodified lines
143144 .. code-block:: text145146 $ git fetch origin141 $ git checkout -b your-branch-name origin/7.x147 $ git checkout -b your-branch-name origin/8.0.x148149 If you're submitting a feature addition or change, branch off of the150 "main" branch.151
71 unmodified lines