Skip to content
Myr

:sparkles: Add support for Click 7.1.1 (#60)

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

* :arrow_up: Upgrade required Click to 7.1.1 and pin it to patch versions as a MINOR version broke compatibility, so I'll have to upgrade manually every time * :pushpin: Fix pinning Click to MINOR version * :sparkles: Upgrade code to be compatible with latest Click changes * :white_check_mark: Update tests with new format for errors * :memo: Update docs to keep them in sync with actual output

authored by Sebastián Ramírez · committed by GitHub · parent e8a30e5 · Browse files · 29 files+39 added−36 removed
This commit

State

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

Diff stats

29 files+39 added−36 removed

  • tests:+15 added−15 removed
  • other:+24 added−21 removed

29 files+39 added−36 removed

modified:docs/tutorial/commands/index.md+1 added-1 removed
modified:docs/tutorial/commands/one-or-multiple.md+1 added-1 removed
13 unmodified lines
1415Usage: main.py [OPTIONS] NAME16Try "main.py --help" for help.1718Error: Missing argument "NAME".18Error: Missing argument 'NAME'.1920// With the NAME CLI argument21$ python main.py Camila22
129 unmodified lines
modified:docs/tutorial/options/required.md+1 added-1 removed
30 unmodified lines
31// We didn't pass the now required --lastname CLI option32Usage: main.py [OPTIONS] NAME33Try "main.py --help" for help.3435Error: Missing option "--lastname".35Error: Missing option '--lastname'.3637// Now update it to pass the required --lastname CLI option38$ python main.py Camila --lastname Gutiérrez39
17 unmodified lines
modified:docs/tutorial/parameter-types/datetime.md+1 added-1 removed
31 unmodified lines
32$ python main.py july-19-19893334Usage: main.py [OPTIONS] [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d%H:%M:%S]3536Error: Invalid value for "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]": invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)36Error: Invalid value for '[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]': invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)37```3839</div>40
39 unmodified lines
modified:docs/tutorial/parameter-types/enum.md+1 added-1 removed
34 unmodified lines
3536Usage: main.py [OPTIONS]37Try "main.py --help" for help.3839Error: Invalid value for "--network": invalid choice: capsule. (choose from simple, conv, lstm)39Error: Invalid value for '--network': invalid choice: capsule. (choose from simple, conv, lstm)40```4142</div>43
25 unmodified lines
modified:docs/tutorial/parameter-types/index.md+1 added-1 removed
47 unmodified lines
4849Usage: main.py [OPTIONS] NAME50Try "main.py --help" for help.5152Error: Invalid value for "--age": 15.3 is not a valid integer52Error: Invalid value for '--age': 15.3 is not a valid integer5354// Because 15.3 is not an INTEGER (it's a float)55```56
9 unmodified lines
modified:docs/tutorial/parameter-types/number.md+4 added-4 removed
36 unmodified lines
3738Usage: main.py [OPTIONS] ID39Try "main.py --help" for help.4041Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.41Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000.4243// Pass an invalid age44$ python main.py 5 --age 154546Usage: main.py [OPTIONS] ID47Try "main.py --help" for help.4849Error: Invalid value for "--age": 15 is smaller than the minimum valid value 18.49Error: Invalid value for '--age': 15 is smaller than the minimum valid value 18.5051// Pass an invalid score52$ python main.py 5 --age 20 --score 100.55354Usage: main.py [OPTIONS] ID55Try "main.py --help" for help.5657Error: Invalid value for "--score": 100.5 is bigger than the maximum valid value 100.57Error: Invalid value for '--score': 100.5 is bigger than the maximum valid value 100.5859// But as we didn't specify a minimum score, this is accepted60$ python main.py 5 --age 20 --score -561
24 unmodified lines
8687Usage: main.py [OPTIONS] ID88Try "main.py --help" for help.8990Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.90Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000.9192// But --rank and --score use clamp93$ python main.py 5 --rank 11 --score -594
54 unmodified lines
modified:docs/tutorial/parameter-types/path.md+2 added-2 removed
71 unmodified lines
7273Usage: main.py [OPTIONS]74Try "main.py --help" for help.7576Error: Invalid value for "--config": File "config.txt" does not exist.76Error: Invalid value for '--config': File 'config.txt' does not exist.7778// Now create a quick config79$ echo "some settings" > config.txt80
7 unmodified lines
8889Usage: main.py [OPTIONS]90Try "main.py --help" for help.9192Error: Invalid value for "--config": File "./" is a directory.92Error: Invalid value for '--config': File './' is a directory.93```9495</div>96
9 unmodified lines
modified:docs/tutorial/parameter-types/uuid.md+1 added-1 removed
40 unmodified lines
4142Usage: main.py [OPTIONS] USER_ID43Try "main.py --help" for help.4445Error: Invalid value for "USER_ID": 7479706572-72756c6573 is not a valid UUID value45Error: Invalid value for 'USER_ID': 7479706572-72756c6573 is not a valid UUID value46```4748</div>
modified:docs/tutorial/arguments.md+1 added-1 removed
80 unmodified lines
8182Usage: main.py [OPTIONS] NAME83Try "main.py --help" for help.8485Error: Missing argument "NAME".85Error: Missing argument 'NAME'.86```8788</div>89
119 unmodified lines
modified:docs/tutorial/first-steps.md+2 added-2 removed
77 unmodified lines
7879Usage: main.py [OPTIONS] NAME80Try "main.py --help" for help.8182Error: Missing argument "NAME".82Error: Missing argument 'NAME'.8384// Now pass that NAME CLI argument85$ python main.py Camila86
40 unmodified lines
127128Usage: main.py [OPTIONS] NAME LASTNAME129Try "main.py --help" for help.130131Error: Missing argument "LASTNAME".131Error: Missing argument 'LASTNAME'.132133// These 2 arguments are required, so, pass both:134$ python main.py Camila Gutiérrez135
303 unmodified lines
modified:docs/index.md+1 added-1 removed
84 unmodified lines
85// You get a nice error, you are missing NAME86Usage: main.py [OPTIONS] NAME87Try "main.py --help" for help.8889Error: Missing argument "NAME".89Error: Missing argument 'NAME'.9091// You get a --help for free92$ python main.py --help93
181 unmodified lines
modified:tests/test_tutorial/test_arguments/test_tutorial001.py+1 added-1 removed
12 unmodified lines
1314def test_call_no_arg():15 result = runner.invoke(app)16 assert result.exit_code != 017 assert 'Error: Missing argument "NAME".' in result.output17 assert "Error: Missing argument 'NAME'." in result.output181920def test_call_arg():21 result = runner.invoke(app, ["Camila"])
12 unmodified lines
modified:tests/test_tutorial/test_commands/test_index/test_tutorial001.py+1 added-1 removed
9 unmodified lines
1011def test_no_arg():12 result = runner.invoke(app)13 assert result.exit_code != 014 assert 'Error: Missing argument "NAME".' in result.output14 assert "Error: Missing argument 'NAME'." in result.output151617def test_arg():18 result = runner.invoke(app, ["Camila"])
12 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial002.py+1 added-1 removed
12 unmodified lines
1314def test_1():15 result = runner.invoke(app, [])16 assert result.exit_code != 017 assert 'Error: Missing argument "NAME"' in result.output17 assert "Error: Missing argument 'NAME'" in result.output181920def test_2():21 result = runner.invoke(app, ["Camila"])
12 unmodified lines
modified:tests/test_tutorial/test_first_steps/test_tutorial003.py+1 added-1 removed
12 unmodified lines
1314def test_1():15 result = runner.invoke(app, ["Camila"])16 assert result.exit_code != 017 assert 'Error: Missing argument "LASTNAME"' in result.output17 assert "Error: Missing argument 'LASTNAME'" in result.output181920def test_2():21 result = runner.invoke(app, ["Camila", "Gutiérrez"])
12 unmodified lines
modified:tests/test_tutorial/test_options/test_required/test_tutorial002.py+1 added-1 removed
12 unmodified lines
1314def test_1():15 result = runner.invoke(app, ["Camila"])16 assert result.exit_code != 017 assert 'Error: Missing option "--lastname".' in result.output17 assert "Error: Missing option '--lastname'." in result.output181920def test_option_lastname():21 result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"])
19 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py+1 added-1 removed
26 unmodified lines
27def test_invalid():28 result = runner.invoke(app, ["july-19-1989"])29 assert result.exit_code != 030 assert (31 'Error: Invalid value for "[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]": invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)'31 "Error: Invalid value for '[%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d %H:%M:%S]': invalid datetime format: july-19-1989. (choose from %Y-%m-%d, %Y-%m-%dT%H:%M:%S, %Y-%m-%d %H:%M:%S)"32 in result.output33 )3435
8 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py+1 added-1 removed
25 unmodified lines
26def test_invalid():27 result = runner.invoke(app, ["--network", "capsule"])28 assert result.exit_code != 029 assert (30 'Error: Invalid value for "--network": invalid choice: capsule. (choose from simple, conv, lstm)'30 "Error: Invalid value for '--network': invalid choice: capsule. (choose from simple, conv, lstm)"31 in result.output32 )3334
8 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py+1 added-1 removed
31 unmodified lines
32def test_invalid():33 result = runner.invoke(app, ["Camila", "--age", "15.3"])34 assert result.exit_code != 035 assert (36 'Error: Invalid value for "--age": 15.3 is not a valid integer' in result.output36 "Error: Invalid value for '--age': 15.3 is not a valid integer" in result.output37 )383940def test_script():
7 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py+3 added-3 removed
28 unmodified lines
29def test_invalid_id():30 result = runner.invoke(app, ["1002"])31 assert result.exit_code != 032 assert (33 'Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.'33 "Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000."34 in result.output35 )363738def test_invalid_age():39 result = runner.invoke(app, ["5", "--age", "15"])40 assert result.exit_code != 041 assert (42 'Error: Invalid value for "--age": 15 is smaller than the minimum valid value 18.'42 "Error: Invalid value for '--age': 15 is smaller than the minimum valid value 18."43 in result.output44 )454647def test_invalid_score():48 result = runner.invoke(app, ["5", "--age", "20", "--score", "100.5"])49 assert result.exit_code != 050 assert (51 'Error: Invalid value for "--score": 100.5 is bigger than the maximum valid value 100.'51 "Error: Invalid value for '--score': 100.5 is bigger than the maximum valid value 100."52 in result.output53 )5455
16 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial002.py+1 added-1 removed
13 unmodified lines
14def test_invalid_id():15 result = runner.invoke(app, ["1002"])16 assert result.exit_code != 017 assert (18 'Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.'18 "Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000."19 in result.output20 )2122
16 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py+2 added-2 removed
16 unmodified lines
17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 result = runner.invoke(app, ["--config", f"{config_file}"])20 assert result.exit_code != 021 assert 'Error: Invalid value for "--config": File' in result.output21 assert "Error: Invalid value for '--config': File" in result.output22 assert "does not exist" in result.output232425def test_exists(tmpdir):
8 unmodified lines
34def test_dir():35 result = runner.invoke(app, ["--config", "./"])36 assert result.exit_code != 037 assert (38 'Error: Invalid value for "--config": File "./" is a directory.'38 "Error: Invalid value for '--config': File './' is a directory."39 in result.output40 )4142
8 unmodified lines
modified:tests/test_tutorial/test_parameter_types/test_uuid/test_tutorial001.py+1 added-1 removed
20 unmodified lines
21def test_invalid_uuid():22 result = runner.invoke(app, ["7479706572-72756c6573"])23 assert result.exit_code != 024 assert (25 'Error: Invalid value for "USER_ID": 7479706572-72756c6573 is not a valid UUID value'25 "Error: Invalid value for 'USER_ID': 7479706572-72756c6573 is not a valid UUID value"26 in result.output27 )2829
8 unmodified lines
modified:typer/main.py+3 added
139 unmodified lines
140 epilog: Optional[str] = None,141 short_help: Optional[str] = None,142 options_metavar: str = "[OPTIONS]",143 add_help_option: bool = True,144 no_args_is_help: bool = False,145 hidden: bool = False,146 deprecated: bool = False,147 ) -> Callable[[CommandFunctionType], CommandFunctionType]:148 if cls is None:
10 unmodified lines
159 epilog=epilog,160 short_help=short_help,161 options_metavar=options_metavar,162 add_help_option=add_help_option,163 no_args_is_help=no_args_is_help,164 hidden=hidden,165 deprecated=deprecated,166 )167 )
270 unmodified lines
438 epilog=command_info.epilog,439 short_help=command_info.short_help,440 options_metavar=command_info.options_metavar,441 add_help_option=command_info.add_help_option,442 no_args_is_help=command_info.no_args_is_help,443 hidden=command_info.hidden,444 deprecated=command_info.deprecated,445 )446 return command
300 unmodified lines
modified:typer/models.py+2 added
86 unmodified lines
87 epilog: Optional[str] = None,88 short_help: Optional[str] = None,89 options_metavar: str = "[OPTIONS]",90 add_help_option: bool = True,91 no_args_is_help: bool = False,92 hidden: bool = False,93 deprecated: bool = False,94 ):95 self.name = name
4 unmodified lines
100 self.epilog = epilog101 self.short_help = short_help102 self.options_metavar = options_metavar103 self.add_help_option = add_help_option104 self.no_args_is_help = no_args_is_help105 self.hidden = hidden106 self.deprecated = deprecated107108
284 unmodified lines
modified:typer/testing.py-2 removed
11 unmodified lines
12 input: Optional[Union[bytes, Text, IO[Any]]] = None,13 env: Optional[Mapping[str, str]] = None,14 catch_exceptions: bool = True,15 color: bool = False,16 mix_stderr: bool = False,16 **extra: Any,17 ) -> Result:18 use_cli = _get_command(app)19 return super().invoke(
2 unmodified lines
22 input=input,23 env=env,24 catch_exceptions=catch_exceptions,25 color=color,27 mix_stderr=mix_stderr,26 **extra,27 )
modified:pyproject.toml+1 added-1 removed
25 unmodified lines
26 "Programming Language :: Python :: 3.8",27 "License :: OSI Approved :: MIT License"28 ]29requires = [30 "click >= 7.0.0, <8.0.0"30 "click >= 7.1.1, <7.2.0"31]32description-file = "README.md"33requires-python = ">=3.6"34
24 unmodified lines
modified:README.md+1 added-1 removed
84 unmodified lines
85// You get a nice error, you are missing NAME86Usage: main.py [OPTIONS] NAME87Try "main.py --help" for help.8889Error: Missing argument "NAME".89Error: Missing argument 'NAME'.9091// You get a --help for free92$ python main.py --help93
181 unmodified lines