:memo: Refactor docs with internal links #38
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parents 62fd577, 222765e · Browse files · 18 files·+50 added−46 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
18 files+50 added−46 removed
- tests:+22 added−28 removed
- other:+28 added−18 removed
Provenance
- Commit
8d6b201- Tree
97dff0d- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
62fd577- Parent 2
222765e
18 files changed+50 added−46 removed
modified:docs/css/custom.css+11 added-1 removed
7 unmodified lines891011121314121516171819202122237 unmodified lines white-space: pre-wrap;}
a.external-link::after { /* \00A0 is a non-breaking space to make the mark be on the same line as the link */ content: " [↪]"; content: "\00A0[↪]";}
a.internal-link::after { /* \00A0 is a non-breaking space to make the mark be on the same line as the link */ content: "\00A0↪";}modified:docs/tutorial/subcommands/callback-override.md+1 added-1 removed
49 unmodified lines5051525354545556575846 unmodified lines49 unmodified lines## Overriding the callback on creation
If a callback was added when creating the `typer.Typer()` app, it's possible to override it with a new one using `@app.callback()`.
This is the same information you saw on the section about <a href="https://typer.tiangolo.com/tutorial/commands/callback/" class="external-link" target="_blank">Commands - Typer Callback</a>, and it applies the same for sub-Typer apps:This is the same information you saw on the section about [Commands - Typer Callback](../commands/callback.md){.internal-link target=_blank}, and it applies the same for sub-Typer apps:
```Python hl_lines="6 7 10 14 15 16"{!./src/subcommands/callback_override/tutorial003.py!}```46 unmodified linesmodified:docs/tutorial/subcommands/index.md+1 added-1 removed
11234534 unmodified linesYou read before how to create a program with <a href="https://typer.tiangolo.com/tutorial/commands/" class="external-link" target="_blank">Commands</a>.You read before how to create a program with [Commands](../commands/index.md){.internal-link target=_blank}.
Now we'll see how to create a *CLI program* with commands that have their own subcommands. Also known as command groups.
For example, the *CLI program* `git` has a command `remote`.34 unmodified linesmodified:docs/tutorial/arguments.md+2 added-2 removed
33 unmodified lines34 </div>35 36 ### An alternative *CLI argument* declaration37 38-In the <a href="https://typer.tiangolo.com/tutorial/first-steps/#add-a-cli-argument" class="external-link" target="_blank">First Steps</a> you saw how to add a *CLI argument*:38+In the [First Steps](first-steps.md#add-a-cli-argument){.internal-link target=_blank} you saw how to add a *CLI argument*:39 40 ```Python hl_lines="4"41 {!./src/first_steps/tutorial002.py!}42 ```147 unmodified lines190 For that reason, Typer (actually Click underneath) doesn't attempt to automatically document *CLI arguments*.191 192 And you should document them as part of the CLI app documentation, normally in a <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>.193 194-Check the last example from the <a href="https://typer.tiangolo.com/tutorial/first-steps/#document-your-cli-app" class="external-link" target="_blank">First Steps</a>:194+Check the last example from the [First Steps](first-steps.md#document-your-cli-app){.internal-link target=_blank}:195 196 ```Python hl_lines="5 6 7 8 9"197 {!./src/first_steps/tutorial006.py!}198 ```10 unmodified linesmodified:docs/tutorial/first-steps.md+2 added-2 removed
387 unmodified lines388 It's quite technical... and somewhat pedantic.389 390 One refers to the variable name in a function *declaration*. Like:391 392- ```Python392+ ```393 def bring_person(name: str, lastname: str = ""):394 pass395 ```396 397 The other refers to the value passed when *calling* a function. Like:398 399- ```Python399+ ```400 person = bring_person("Camila", lastname="Gutiérrez")401 ```402 403 ...but you will probably see them used interchangeably in most of the places (including here).35 unmodified linesmodified:docs/tutorial/index.md+1 added-1 removed
1 ## Python types2 3-If you need a refreshed about how to use Python type hints, check the first part of <a href="https://fastapi.tiangolo.com/python-types/" target="_blank">FastAPI's Python types intro</a>.3+If you need a refreshed about how to use Python type hints, check the first part of <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.4 5 You can also check the <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">mypy cheat sheet</a>.6 7 In short (very short), you can declare a function with parameters like:69 unmodified linesmodified:docs/tutorial/prompt.md+2 added-2 removed
1-When you need to ask the user for info interactively you should normally use <a href="https://typer.tiangolo.com/tutorial/options/prompt/" class="external-link" target="_blank">*CLI Option*s with Prompt</a>, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).1+When you need to ask the user for info interactively you should normally use [*CLI Option*s with Prompt](options/prompt.md){.internal-link target=_blank}, because they allow using the CLI program in a non-interactive way (for example, a Bash script could use it).2 3 But if you absolutely need to ask for interactive information without using a *CLI option*, you can use `typer.prompt()`:4 5 ```Python hl_lines="5"15 unmodified lines21 </div>22 23 ## Confirm24 25-There's also an alternative to ask for confirmation. Again, if possible, you should use a <a href="https://typer.tiangolo.com/tutorial/options/prompt/" class="external-link" target="_blank">*CLI Option* with a confirmation prompt</a>:25+There's also an alternative to ask for confirmation. Again, if possible, you should use a [*CLI Option* with a confirmation prompt](options/prompt.md){.internal-link target=_blank}:26 27 ```Python hl_lines="5"28 {!./src/prompt/tutorial002.py!}29 ```49 unmodified linesmodified:docs/contributing.md+1 added-1 removed
1-First, you might want to see the basic ways to <a href="https://typer.tiangolo.com/help-typer/" target="_blank">help Typer and get help</a>.1+First, you might want to see the basic ways to [help Typer and get help](help-typer.md){.internal-link target=_blank}.2 3 Coming soon...4 5 <!-- ## Developing120 unmodified linesmodified:docs/features.md+3 added-3 removed
1 ## Design based on **FastAPI**2 3-**Typer** is <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>'s little sibling.3+**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling.4 5 It follows the same design and ideas. If you know FastAPI, you already know **Typer**... more or less.6 7 ## Just Modern Python8 9 It's all based on standard **Python 3.6 type** declarations. No new syntax to learn. Just standard modern Python.10 11-If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI or Typer), check the FastAPI tutorial section: <a href="https://fastapi.tiangolo.com/python-types/" target="_blank">Python types intro</a>.11+If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI or Typer), check the FastAPI tutorial section: <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">Python types intro</a>.12 13-You will also see a 20 seconds refresher on the section [Tutorial - User Guide: First Steps](tutorial/first-steps.md).13+You will also see a 20 seconds refresher on the section [Tutorial - User Guide: First Steps](tutorial/first-steps.md){.internal-link target=_blank}.14 15 ## Editor support16 17 **Typer** was designed to be easy and intuitive to use, to ensure the best development experience. With autocompletion everywhere.60 unmodified linesmodified:docs/index.md+2 added-2 removed
24 unmodified lines25 ---26 27 Typer is library to build <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will love using and developers will love creating. Based on Python 3.6+ type hints.28 29-**Typer** is <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>'s little sibling. And it's intended to be the FastAPI of CLIs.29+**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling. And it's intended to be the FastAPI of CLIs.30 31 The key features are:32 33 * **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.208 unmodified lines242 **You get**: great editor support, including **completion** and **type checks** everywhere.243 244 **Your users get**: automatic **`--help`**, (optional) **autocompletion** in their terminal (Bash, Zsh, Fish, PowerShell).245 246-For a more complete example including more features, see the <a href="https://typer.tiangolo.com/tutorial/intro/">Tutorial - User Guide</a>.246+For a more complete example including more features, see the <a href="https://typer.tiangolo.com/tutorial/">Tutorial - User Guide</a>.247 248 ## Optional Dependencies249 250 Typer uses <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a> internally. That's the only dependency.24 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial001.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 config_file.write_text("some settings\nsome more settings")18 result = runner.invoke(app, ["--config", f"{config_file}"])19 config_file.unlink()20 assert result.exit_code == 012 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial002.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 result = runner.invoke(app, ["--config", f"{config_file}"])20 text = config_file.read_text()14 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial003.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-binary_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ binary_file = Path(tmpdir) / "config.txt"17 binary_file.write_bytes(b"la cig\xc3\xbce\xc3\xb1a trae al ni\xc3\xb1o")18 result = runner.invoke(app, ["--file", f"{binary_file}"])19 binary_file.unlink()20 assert result.exit_code == 011 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial004.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-binary_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ binary_file = Path(tmpdir) / "config.txt"17 if binary_file.exists(): # pragma no cover18 binary_file.unlink()19 result = runner.invoke(app, ["--file", f"{binary_file}"])20 text = binary_file.read_text()15 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_file/test_tutorial005.py+2 added-3 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_main():15+def test_main(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"17 if config_file.exists(): # pragma no cover18 config_file.unlink()19 config_file.write_text("")20 result = runner.invoke(app, ["--config", f"{config_file}"])17 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial001.py+6 added-5 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_no_path():15+def test_no_path(tmpdir):16+ Path(tmpdir) / "config.txt"17 result = runner.invoke(app)18 assert result.exit_code == 119 assert "No config file" in result.output20 assert "Aborted!" in result.output21 22 24-def test_not_exists():23+def test_not_exists(tmpdir):24+ config_file = Path(tmpdir) / "config.txt"25 if config_file.exists(): # pragma no cover26 config_file.unlink()27 result = runner.invoke(app, ["--config", f"{config_file}"])28 assert result.exit_code == 029 assert "The config doesn't exist" in result.output30 31 32-def test_exists():32+def test_exists(tmpdir):33+ config_file = Path(tmpdir) / "config.txt"34 config_file.write_text("some settings")35 result = runner.invoke(app, ["--config", f"{config_file}"])36 config_file.unlink()37 assert result.exit_code == 017 unmodified linesmodified:tests/test_tutorial/test_parameter_types/test_path/test_tutorial002.py+6 added-8 removed
9 unmodified lines10 11 app = typer.Typer()12 app.command()(mod.main)13 14-config_file = Path("./config.txt")14 16-17-def test_not_exists():15+def test_not_exists(tmpdir):16+ config_file = Path(tmpdir) / "config.txt"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 != 022- assert (23- 'Error: Invalid value for "--config": File "config.txt" does not exist.'24- in result.output25- )21+ assert 'Error: Invalid value for "--config": File' in result.output22+ assert "does not exist" in result.output23 24 28-def test_exists():25+def test_exists(tmpdir):26+ config_file = Path(tmpdir) / "config.txt"27 config_file.write_text("some settings")28 result = runner.invoke(app, ["--config", f"{config_file}"])29 config_file.unlink()30 assert result.exit_code == 020 unmodified linesmodified:README.md+2 added-2 removed
24 unmodified lines25 ---26 27 Typer is library to build <abbr title="command line interface, programs executed from a terminal">CLI</abbr> applications that users will love using and developers will love creating. Based on Python 3.6+ type hints.28 29-**Typer** is <a href="https://fastapi.tiangolo.com" target="_blank">FastAPI</a>'s little sibling. And it's intended to be the FastAPI of CLIs.29+**Typer** is <a href="https://fastapi.tiangolo.com" class="external-link" target="_blank">FastAPI</a>'s little sibling. And it's intended to be the FastAPI of CLIs.30 31 The key features are:32 33 * **Intuitive to write**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.208 unmodified lines242 **You get**: great editor support, including **completion** and **type checks** everywhere.243 244 **Your users get**: automatic **`--help`**, (optional) **autocompletion** in their terminal (Bash, Zsh, Fish, PowerShell).245 246-For a more complete example including more features, see the <a href="https://typer.tiangolo.com/tutorial/intro/">Tutorial - User Guide</a>.246+For a more complete example including more features, see the <a href="https://typer.tiangolo.com/tutorial/">Tutorial - User Guide</a>.247 248 ## Optional Dependencies249 250 Typer uses <a href="https://click.palletsprojects.com/" class="external-link" target="_blank">Click</a> internally. That's the only dependency.24 unmodified lines