: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
Provenance
- Commit
96b29e9- Tree
8540363- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
e8a30e5
29 files changed+39 added−36 removed
modified:docs/tutorial/commands/index.md+1 added-1 removed
92 unmodified lines939495969797989910010181 unmodified lines92 unmodified lines
Usage: main.py [OPTIONS] NAMETry "main.py --help" for help.
Error: Missing argument "NAME".Error: Missing argument 'NAME'.
// With the NAME CLI argument$ python main.py Camila
81 unmodified linesmodified:docs/tutorial/commands/one-or-multiple.md+1 added-1 removed
13 unmodified lines14 15 Usage: main.py [OPTIONS] NAME16 Try "main.py --help" for help.17 18-Error: Missing argument "NAME".18+Error: Missing argument 'NAME'.19 20 // With the NAME CLI argument21 $ python main.py Camila22 129 unmodified linesmodified:docs/tutorial/options/required.md+1 added-1 removed
30 unmodified lines31 // We didn't pass the now required --lastname CLI option32 Usage: main.py [OPTIONS] NAME33 Try "main.py --help" for help.34 35-Error: Missing option "--lastname".35+Error: Missing option '--lastname'.36 37 // Now update it to pass the required --lastname CLI option38 $ python main.py Camila --lastname Gutiérrez39 17 unmodified linesmodified:docs/tutorial/parameter-types/datetime.md+1 added-1 removed
31 unmodified lines32 $ python main.py july-19-198933 34 Usage: main.py [OPTIONS] [%Y-%m-%d|%Y-%m-%dT%H:%M:%S|%Y-%m-%d%H:%M:%S]35 36-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)36+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)37 ```38 39 </div>40 39 unmodified linesmodified:docs/tutorial/parameter-types/enum.md+1 added-1 removed
34 unmodified lines35 36 Usage: main.py [OPTIONS]37 Try "main.py --help" for help.38 39-Error: Invalid value for "--network": invalid choice: capsule. (choose from simple, conv, lstm)39+Error: Invalid value for '--network': invalid choice: capsule. (choose from simple, conv, lstm)40 ```41 42 </div>43 25 unmodified linesmodified:docs/tutorial/parameter-types/index.md+1 added-1 removed
47 unmodified lines48 49 Usage: main.py [OPTIONS] NAME50 Try "main.py --help" for help.51 52-Error: Invalid value for "--age": 15.3 is not a valid integer52+Error: Invalid value for '--age': 15.3 is not a valid integer53 54 // Because 15.3 is not an INTEGER (it's a float)55 ```56 9 unmodified linesmodified:docs/tutorial/parameter-types/number.md+4 added-4 removed
36 unmodified lines37 38 Usage: main.py [OPTIONS] ID39 Try "main.py --help" for help.40 41-Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.41+Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000.42 43 // Pass an invalid age44 $ python main.py 5 --age 1545 46 Usage: main.py [OPTIONS] ID47 Try "main.py --help" for help.48 49-Error: Invalid value for "--age": 15 is smaller than the minimum valid value 18.49+Error: Invalid value for '--age': 15 is smaller than the minimum valid value 18.50 51 // Pass an invalid score52 $ python main.py 5 --age 20 --score 100.553 54 Usage: main.py [OPTIONS] ID55 Try "main.py --help" for help.56 57-Error: Invalid value for "--score": 100.5 is bigger than the maximum valid value 100.57+Error: Invalid value for '--score': 100.5 is bigger than the maximum valid value 100.58 59 // But as we didn't specify a minimum score, this is accepted60 $ python main.py 5 --age 20 --score -561 24 unmodified lines86 87 Usage: main.py [OPTIONS] ID88 Try "main.py --help" for help.89 90-Error: Invalid value for "ID": 1002 is not in the valid range of 0 to 1000.90+Error: Invalid value for 'ID': 1002 is not in the valid range of 0 to 1000.91 92 // But --rank and --score use clamp93 $ python main.py 5 --rank 11 --score -594 54 unmodified linesmodified:docs/tutorial/parameter-types/path.md+2 added-2 removed
71 unmodified lines72 73 Usage: main.py [OPTIONS]74 Try "main.py --help" for help.75 76-Error: Invalid value for "--config": File "config.txt" does not exist.76+Error: Invalid value for '--config': File 'config.txt' does not exist.77 78 // Now create a quick config79 $ echo "some settings" > config.txt80 7 unmodified lines88 89 Usage: main.py [OPTIONS]90 Try "main.py --help" for help.91 92-Error: Invalid value for "--config": File "./" is a directory.92+Error: Invalid value for '--config': File './' is a directory.93 ```94 95 </div>96 9 unmodified linesmodified:docs/tutorial/parameter-types/uuid.md+1 added-1 removed
40 unmodified lines41 42 Usage: main.py [OPTIONS] USER_ID43 Try "main.py --help" for help.44 45-Error: Invalid value for "USER_ID": 7479706572-72756c6573 is not a valid UUID value45+Error: Invalid value for 'USER_ID': 7479706572-72756c6573 is not a valid UUID value46 ```47 48 </div>modified:docs/tutorial/arguments.md+1 added-1 removed
80 unmodified lines81 82 Usage: main.py [OPTIONS] NAME83 Try "main.py --help" for help.84 85-Error: Missing argument "NAME".85+Error: Missing argument 'NAME'.86 ```87 88 </div>89 119 unmodified linesmodified:docs/tutorial/first-steps.md+2 added-2 removed
77 unmodified lines78 79 Usage: main.py [OPTIONS] NAME80 Try "main.py --help" for help.81 82-Error: Missing argument "NAME".82+Error: Missing argument 'NAME'.83 84 // Now pass that NAME CLI argument85 $ python main.py Camila86 40 unmodified lines127 128 Usage: main.py [OPTIONS] NAME LASTNAME129 Try "main.py --help" for help.130 131-Error: Missing argument "LASTNAME".131+Error: Missing argument 'LASTNAME'.132 133 // These 2 arguments are required, so, pass both:134 $ python main.py Camila Gutiérrez135 303 unmodified linesmodified:docs/index.md+1 added-1 removed
84 unmodified lines85 // You get a nice error, you are missing NAME86 Usage: main.py [OPTIONS] NAME87 Try "main.py --help" for help.88 89-Error: Missing argument "NAME".89+Error: Missing argument 'NAME'.90 91 // You get a --help for free92 $ python main.py --help93 181 unmodified linesmodified:tests/test_tutorial/test_arguments/test_tutorial001.py+1 added-1 removed
12 unmodified lines13 14 def 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.output18 19 20 def test_call_arg():21 result = runner.invoke(app, ["Camila"])12 unmodified linesmodified:tests/test_tutorial/test_commands/test_index/test_tutorial001.py+1 added-1 removed
9 unmodified lines10 11 def 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.output15 16 17 def test_arg():18 result = runner.invoke(app, ["Camila"])12 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial002.py+1 added-1 removed
12 unmodified lines13 14 def 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.output18 19 20 def test_2():21 result = runner.invoke(app, ["Camila"])12 unmodified linesmodified:tests/test_tutorial/test_first_steps/test_tutorial003.py+1 added-1 removed
12 unmodified lines13 14 def 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.output18 19 20 def test_2():21 result = runner.invoke(app, ["Camila", "Gutiérrez"])12 unmodified linesmodified:tests/test_tutorial/test_options/test_required/test_tutorial002.py+1 added-1 removed
12 unmodified lines13 14 def 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.output18 19 20 def test_option_lastname():21 result = runner.invoke(app, ["Camila", "--lastname", "Gutiérrez"])19 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_datetime/test_tutorial001.py+1 added-1 removed
26 unmodified lines27 def 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 )34 35 8 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py+1 added-1 removed
25 unmodified lines26 def 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 )33 34 8 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_index/test_tutorial001.py+1 added-1 removed
31 unmodified lines32 def 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 )38 39 40 def test_script():7 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial001.py+3 added-3 removed
28 unmodified lines29 def 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 )36 37 38 def 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 )45 46 47 def 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 )54 55 16 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_number/test_tutorial002.py+1 added-1 removed
13 unmodified lines14 def 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 )21 22 16 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py+2 added-2 removed
16 unmodified lines17 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.output23 24 25 def test_exists(tmpdir):8 unmodified lines34 def 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 )41 42 8 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_uuid/test_tutorial001.py+1 added-1 removed
20 unmodified lines21 def 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 )28 29 8 unmodified linesmodified:typer/main.py+3 added
139 unmodified lines140 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 lines159 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 lines438 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 command300 unmodified linesmodified:typer/models.py+2 added
86 unmodified lines87 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 = name4 unmodified lines100 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 = deprecated107 108 284 unmodified linesmodified:typer/testing.py-2 removed
11 unmodified lines12 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 lines22 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 lines26 "Programming Language :: Python :: 3.8",27 "License :: OSI Approved :: MIT License"28 ]29 requires = [30- "click >= 7.0.0, <8.0.0"30+ "click >= 7.1.1, <7.2.0"31 ]32 description-file = "README.md"33 requires-python = ">=3.6"34 24 unmodified linesmodified:README.md+1 added-1 removed
84 unmodified lines85 // You get a nice error, you are missing NAME86 Usage: main.py [OPTIONS] NAME87 Try "main.py --help" for help.88 89-Error: Missing argument "NAME".89+Error: Missing argument 'NAME'.90 91 // You get a --help for free92 $ python main.py --help93 181 unmodified lines