📝 Update and simplify usage of admonitions (#1755)
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 · parent 8c47e39 · Browse files · 20 files·+30 added−42 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+30 added−42 removed
- other:+30 added−42 removed
Provenance
- Commit
e3f56c0- Tree
e2c2785- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
8c47e39
20 files changed+30 added−42 removed
modified:docs/tutorial/arguments/help.md+1 added-1 removed
248 unmodified lines249 ```250 251 </div>252 253-/// info253+/// note254 255 Have in mind that the *CLI argument* will still show up in the first line with `Usage`.256 257 But it won't show up in the main help text under the `Arguments` section.10 unmodified linesmodified:docs/tutorial/arguments/optional.md+2 added-2 removed
43 unmodified lines44 Or, using an explicit `Typer()` instance creation:45 46 {* docs_src/arguments/optional/tutorial001_an_py310.py hl[9] *}47 48-/// info48+/// note49 50 Typer added support for `Annotated` (and started recommending it) in version 0.9.0.51 52 If you have an older version, you would get errors when trying to use `Annotated`.155 unmodified lines208 ```Python209 name: str = typer.Argument(default=...)210 ```211 212-/// info212+/// note213 214 If you hadn't seen that `...` before: it is a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.215 216 ///22 unmodified linesmodified:docs/tutorial/commands/help.md+2 added-2 removed
202 unmodified lines203 ## Rich Markdown and Markup204 205 Typer installs **Rich** to allow for more formatting in the docstrings and the `help` parameter for *CLI arguments* and *CLI options*. You will see more about it below. 👇206 207-/// info207+/// note208 209 You can disable rich text formatting by setting `rich_markup_mode` to `None` for your specific app.210 Alternatively, you can disable it globally using an environmental variable `TYPER_USE_RICH` set to `False` or `0`.211 125 unmodified lines337 ```338 339 </div>340 341-/// info341+/// note342 343 Notice that in Markdown you cannot define colors. For colors you might prefer to use Rich markup.344 345 ///159 unmodified linesmodified:docs/tutorial/multiple-values/arguments-with-multiple-values.md+1 added-1 removed
25 unmodified lines2627282930303132333444 unmodified lines25 unmodified linesWe also declared a final *CLI argument* `celebration`, and it's correctly used even if we pass an arbitrary number of `files` first.
///
/// info/// note
A `list` can only be used in the last command (if there are subcommands), as this will take anything to the right and assume it's part of the expected *CLI arguments*.
///44 unmodified linesmodified:docs/tutorial/options/name.md+1 added-1 removed
28 unmodified lines29 You can pass the *CLI option* name that you want to have in the following positional argument passed to `typer.Option()`:30 31 {* docs_src/options/name/tutorial001_an_py310.py hl[9] *}32 33-/// info33+/// note34 35 "<a href="https://docs.python.org/3.8/glossary.html#term-argument" class="external-link" target="_blank">Positional</a>" means that it's not a function argument with a keyword name.36 37 For example `show_default=True` is a keyword argument. "`show_default`" is the keyword.280 unmodified linesmodified:docs/tutorial/options/required.md+1 added-1 removed
21 unmodified lines2223242526262728293041 unmodified lines21 unmodified linesOr you can explicitly pass `...` to `typer.Option(default=...)`:
{* docs_src/options/required/tutorial002_py310.py hl[7] *}
/// info/// note
If you hadn't seen that `...` before: it is a special single value, it is <a href="https://docs.python.org/3/library/constants.html#Ellipsis" class="external-link" target="_blank">part of Python and is called "Ellipsis"</a>.
///41 unmodified linesmodified:docs/tutorial/options/version.md+1 added-1 removed
82 unmodified lines83 `typer.BadParameter` prints the error to "standard error", not to "standard output", and because the completion system only reads from "standard output", it won't break completion.84 85 ///86 87-/// info87+/// note88 89 If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](../printing.md#standard-output-and-standard-error){.internal-link target=_blank}.90 91 ///21 unmodified linesmodified:docs/tutorial/parameter-types/file.md+1 added-1 removed
100 unmodified lines101 ```102 103 </div>104 105-/// info | Technical Details105+/// note | Technical Details106 107 `typer.FileTextWrite` is a just a convenience class.108 109 It's the same as using `typer.FileText` and setting `mode="w"`. You will learn about `mode` later below.125 unmodified linesmodified:docs/tutorial/parameter-types/uuid.md+1 added-1 removed
1 # UUID2 3-/// info3+/// note4 5 A UUID is a <a href="https://en.wikipedia.org/wiki/Universally_unique_identifier" class="external-link" target="_blank">"Universally Unique Identifier"</a>.6 7 It's a standard format for identifiers, like passport numbers, but for anything, not just people in countries.42 unmodified linesmodified:docs/tutorial/subcommands/name-and-help.md+1 added-1 removed
303 unmodified lines304 You can set it when creating a new `typer.Typer()`:305 306 {* docs_src/subcommands/name_help/tutorial006_py310.py hl[12] *}307 308-/// info308+/// note309 310 The rest of the callbacks and overrides are there only to show you that they don't affect the name and help text when you set it explicitly.311 312 ///147 unmodified linesmodified:docs/tutorial/options-autocompletion.md+3 added-3 removed
126 unmodified lines127 In the end, the return will be a `list` (or other iterable) of `tuples` of 2 `str`.128 129 ///130 131-/// info131+/// note132 133 The help text will be visible in Zsh, Fish, and PowerShell.134 135 Bash doesn't support showing the help text, but completion will still work the same.32 unmodified lines168 In the end, that's just to save us a couple of lines of code.169 170 ///171 172-/// info172+/// note173 174 The function can use `yield`, so it doesn't have to return strictly a `list`, it just has to be <a href="https://docs.python.org/3.8/glossary.html#term-iterable" class="external-link" target="_blank">iterable</a>.175 176 But each of the elements for completion has to be a `str` or a `tuple` (when containing a help text).118 unmodified lines295 Using `stderr=True` tells **Rich** that the output should be shown in "standard error".296 297 {* docs_src/options_autocompletion/tutorial008_an_py310.py hl[12,15:16] *}298 299-/// info299+/// note300 301 If you have disabled Rich, you can also use `print(lastname, file=sys.stderr)` or `typer.echo("some text", err=True)` instead.302 303 ///81 unmodified linesmodified:docs/tutorial/printing.md+1 added-1 removed
128 unmodified lines129 And there's another "**virtual file**" called "**standard error**" that is normally only used for errors.130 131 But we can also "print" to "standard error". And both are shown on the terminal to the users.132 133-/// info133+/// note134 135 If you use PowerShell it's quite possible that what you print to "standard error" won't be shown in the terminal.136 137 In PowerShell, to see "standard error" you would have to check the variable `$Error`.135 unmodified linesmodified:docs/tutorial/progressbar.md+1 added-1 removed
121 unmodified lines122 Notice that there are 2 levels of code blocks. One for the `with` statement and one for the `for` statement.123 124 ///125 126-/// info126+/// note127 128 This is mostly useful for operations that take some time.129 130 In the example above we are faking it with `time.sleep()`.102 unmodified linesmodified:docs/tutorial/testing.md+2 added-2 removed
73 unmodified lines74 You could also check the output sent to "standard error" (`stderr`) or "standard output" (`stdout`) independently by accessing `result.stdout` and `result.stderr` in your tests.75 76 ///77 78-/// info78+/// note79 80 If you need a refresher about what is "standard output" and "standard error" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error){.internal-link target=_blank}.81 82 ///45 unmodified lines128 You can test the input typed in the terminal using `input="camila@example.com\n"`.129 130 This is because what you type in the terminal goes to "**standard input**" and is handled by the operating system as if it was a "virtual file".131 132-/// info132+/// note133 134 If you need a refresher about what is "standard output", "standard error", and "standard input" check the section in [Printing and Colors: "Standard Output" and "Standard Error"](printing.md#standard-output-and-standard-error){.internal-link target=_blank}.135 136 ///78 unmodified linesmodified:docs/tutorial/typer-app.md+1 added-1 removed
18 unmodified lines19 * Create a new `typer.Typer()` "application".20 * Create a new "`command`" with your function.21 * Call the same "application" as if it was a function with "`app()`".22 23-/// info | `@decorator` Info23+/// note | `@decorator` Info24 25 That `@something` syntax in Python is called a "decorator".26 27 You put it on top of a function. Like a pretty decorative hat (I guess that's where the term came from).91 unmodified linesmodified:docs/alternatives.md+6 added-6 removed
14 unmodified lines15 `argparse` is the Python standard library's module to write CLIs.16 17 It provides a better alternative than reading the *CLI Parameters* as a `list` of `str` and parsing everything by hand.18 19-/// check | Inspired **Typer** to19+/// tip | Inspired **Typer** to20 21 Provide a better development experience than just reading *CLI Parameters* by hand.22 23 ///3 unmodified lines27 Hug is a library to create APIs and CLIs, it uses parameters in functions to declare the required data.28 29 It inspired a lot of the ideas in **FastAPI** and **Typer**.30 31-/// check | Inspired **Typer** to31+/// tip | Inspired **Typer** to32 33 Use function parameters to declare *CLI arguments* and *CLI options* as it simplifies a lot the development experience.34 35 ///1 unmodified line37 ### <a href="https://plac.readthedocs.io/en/latest/" class="external-link" target="_blank">Plac</a>38 39 Plac is another library to create CLIs using parameters in functions, similar to Hug.40 41-/// check | Inspired **Typer** to41+/// tip | Inspired **Typer** to42 43 Provide a simple way to use a function as a command line app, without having to create a complete app, with `typer.run(some_function)`.44 45 ///5 unmodified lines51 It powers **FastAPI** underneath.52 53 It is not used by **Typer**, but it inspired a lot of the design (through **FastAPI**).54 55-/// check | Inspired **Typer** to55+/// tip | Inspired **Typer** to56 57 Use standard Python type annotations to declare types instead of library-specific types or classes and use them for data validation and documentation.58 59 ///9 unmodified lines69 It uses decorators on top of functions to modify the actual value of those functions, converting them to instances of a specific class. This is a clever trick, but code editors can't provide great support for autocompletion that way.70 71 It was built with some great ideas and design using the features available in the language at the time (Python 2.x).72 73-/// check | **Typer** uses it for73+/// tip | **Typer** uses it for74 75 Everything. 🚀76 77 **Typer** mainly adds a layer on top of Click, making the code simpler and easier to use, with autocompletion everywhere, etc, but providing all the powerful features of Click underneath.9 unmodified lines87 Previous versions of **Typer** had deep integrations with `click-completion` and used it as an optional dependency. But now all the completion logic is implemented internally in **Typer** itself, the internal logic was heavily inspired and using some parts of `click-completion`.88 89 And now **Typer** improved it to have new features, tests, some bug fixes (for issues in plain `click-completion` and Click), and better support for shells, including modern versions of PowerShell (e.g. the default versions that come with Windows 10).90 91-/// check | Inspired **Typer** to91+/// tip | Inspired **Typer** to92 93 Provide auto completion for all the shells.94 95 ///8 unmodified linesmodified:docs/contributing.md+1 added-1 removed
117 unmodified lines118 ```console119 $ typer --install-completion120 ```121 122-/// info122+/// note123 124 In `pwsh` you will probably get a warning of:125 126 ```plaintext211 unmodified linesmodified:docs/help-typer.md+1 added-1 removed
155 unmodified lines156 * Check and read the code, see if it makes sense, **run it locally** and see if it actually solves the problem.157 158 * Then **comment** saying that you did that, that's how I will know you really checked it.159 160-/// info160+/// note161 162 Unfortunately, I can't simply trust PRs that just have several approvals.163 164 Several times it has happened that there are PRs with 3, 5 or more approvals, probably because the description is appealing, but when I check the PRs, they are actually broken, have a bug, or don't solve the problem they claim to solve. 😅88 unmodified linesmodified:docs/virtual-environments.md+2 added-2 removed
1 # Virtual Environments2 3 When you work in Python projects you probably should use a **virtual environment** (or a similar mechanism) to isolate the packages you install for each project.4 5-/// info5+/// note6 7 If you already know about virtual environments, how to create them and use them, you might want to skip this section. 🤓8 9 ///7 unmodified lines17 A **virtual environment** is a directory with some files in it.18 19 ///20 21-/// info21+/// note22 23 This page will teach you how to use **virtual environments** and how they work.24 25 If you are ready to adopt a **tool that manages everything** for you (including installing Python), try <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">uv</a>.819 unmodified linesmodified:mkdocs.yml-12 removed
197 unmodified lines198 pymdownx.tilde:199 200 # pymdownx blocks201 pymdownx.blocks.admonition:202- types:203- - note204- - attention205- - caution206- - danger207- - error208- - tip209- - hint210- - warning211- # Custom types212- - info213- - check202 pymdownx.blocks.details:203 pymdownx.blocks.tab:204 alternate_style: True205 27 unmodified lines