diff --git a/README.md b/README.md index 5a1d648270..43ae5131df 100644 --- a/README.md +++ b/README.md @@ -356,34 +356,18 @@ For a more complete example including more features, see the Click. - -By default it also comes with extra standard dependencies: +**Typer** stands on the shoulders of giants. It has three required dependencies: +* Click: a popular tool for building CLIs in Python. Typer is based on it. * rich: to show nicely formatted errors automatically. * shellingham: to automatically detect the current shell when installing completion. - * With `shellingham` you can just use `--install-completion`. - * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`. ### `typer-slim` -If you don't want the extra standard optional dependencies, install `typer-slim` instead. - -When you install with: - -```bash -pip install typer -``` - -...it includes the same code and dependencies as: - -```bash -pip install "typer-slim[standard]" -``` - -The `standard` extra dependencies are `rich` and `shellingham`. +There used to be a slimmed-down version of Typer called `typer-slim`, which didn't include the dependencies `rich` and `shellingham`, nor the `typer` command. -**Note**: The `typer` command is only included in the `typer` package. +However, since version 0.22.0, we have stopped supporting this, and `typer-slim` now simply installs (all of) Typer. +If you want to disable Rich globally, you can set an environmental variable "TYPER_USE_RICH" to `False`/`0`. ## License diff --git a/docs/features.md b/docs/features.md index 5a8643fa35..02f7d71046 100644 --- a/docs/features.md +++ b/docs/features.md @@ -54,20 +54,13 @@ The resulting CLI apps created with **Typer** have the nice features of many "pr Auto completion works when you create a package (installable with `pip`). Or when using the `typer` command. -**Typer** uses `shellingham` to auto-detect the current shell when installing completion. If you don't want to include `shellingham`, install `typer-slim`. +**Typer** uses `shellingham` to auto-detect the current shell when installing completion. **Typer** will automatically create 2 *CLI options*: * `--install-completion`: Install completion for the current shell. * `--show-completion`: Show completion for the current shell, to copy it or customize the installation. -If you didn't add `shellingham` (if you installed `pip install typer-slim`) those *CLI options* take a value with the name of the shell to install completion for, e.g.: - -* `--install-completion bash`. -* `--show-completion powershell`. - -Then you can tell the user to install completion after installing your CLI program and the rest will just work. - /// /// tip diff --git a/docs/index.md b/docs/index.md index 12520fe0f5..d4cccdc921 100644 --- a/docs/index.md +++ b/docs/index.md @@ -362,34 +362,18 @@ For a more complete example including more features, see the Click. - -By default it also comes with extra standard dependencies: +**Typer** stands on the shoulders of giants. It has three required dependencies: +* Click: a popular tool for building CLIs in Python. Typer is based on it. * rich: to show nicely formatted errors automatically. * shellingham: to automatically detect the current shell when installing completion. - * With `shellingham` you can just use `--install-completion`. - * Without `shellingham`, you have to pass the name of the shell to install completion for, e.g. `--install-completion bash`. ### `typer-slim` -If you don't want the extra standard optional dependencies, install `typer-slim` instead. - -When you install with: - -```bash -pip install typer -``` - -...it includes the same code and dependencies as: - -```bash -pip install "typer-slim[standard]" -``` - -The `standard` extra dependencies are `rich` and `shellingham`. +There used to be a slimmed-down version of Typer called `typer-slim`, which didn't include the dependencies `rich` and `shellingham`, nor the `typer` command. -**Note**: The `typer` command is only included in the `typer` package. +However, since version 0.22.0, we have stopped supporting this, and `typer-slim` now simply installs (all of) Typer. +If you want to disable Rich globally, you can set an environmental variable "TYPER_USE_RICH" to `False`/`0`. ## License diff --git a/docs/tutorial/commands/help.md b/docs/tutorial/commands/help.md index ae330341da..d82256464d 100644 --- a/docs/tutorial/commands/help.md +++ b/docs/tutorial/commands/help.md @@ -202,19 +202,18 @@ If there are multiple close matches, Typer will suggest them all. This feature u ## Rich Markdown and Markup -If you have **Rich** installed as described in [Printing and Colors](../printing.md){.internal-link target=_blank}, you can configure your app to enable markup text with the parameter `rich_markup_mode`. - -Then you can use more formatting in the docstrings and the `help` parameter for *CLI arguments* and *CLI options*. You will see more about it below. 👇 +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. 👇 /// info -By default, `rich_markup_mode` is `None` if Rich is not installed, and `"rich"` if it is installed. In the latter case, you can set `rich_markup_mode` to `None` to disable rich text formatting. +You can disable rich text formatting by setting `rich_markup_mode` to `None` for your specific app. +Alternatively, you can disable it globally using an environmental variable "TYPER_USE_RICH" set to `False`/`0`. /// ### Rich Markup -If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app, you will be able to use Rich Console Markup in the docstring, and even in the help for the *CLI arguments* and options: +If you set `rich_markup_mode="rich"` when creating the `typer.Typer()` app (which is the default), you will be able to use Rich Console Markup in the docstring, and even in the help for the *CLI arguments* and options: {* docs_src/commands/help/tutorial004_an_py39.py hl[5,11,15:17,22,25,28] *} diff --git a/docs/tutorial/exceptions.md b/docs/tutorial/exceptions.md index 3a87da1ec3..cb1c457a3b 100644 --- a/docs/tutorial/exceptions.md +++ b/docs/tutorial/exceptions.md @@ -14,7 +14,7 @@ This code is broken because you can't sum a string and a number (`name + 3`). ## Exceptions with Rich -If you have **Rich** installed (for example if you installed `"typer[all]"`), **Typer** will use it to automatically show you nicely printed errors. +**Typer** will automatically use Rich to automatically show you nicely printed errors. It will **omit** all the parts of the traceback (the chain of things that called your function) that come from the internal parts in Typer and Click. @@ -47,7 +47,8 @@ $ python main.py ## Exceptions without Rich -If you don't have Rich installed, Typer will still do some tricks to show you the information **as clearly as possible**: +You can disable Rich globally using the environmental variable `TYPER_USE_RICH`. +In this case, Typer will still do some tricks to show you the information **as clearly as possible**:
diff --git a/docs/tutorial/install.md b/docs/tutorial/install.md index 09ee0cfc2c..1a50e24681 100644 --- a/docs/tutorial/install.md +++ b/docs/tutorial/install.md @@ -16,18 +16,8 @@ Successfully installed typer click shellingham rich By default, `typer` comes with `rich` and `shellingham`. -/// note - -If you are an advanced user and want to opt out of these default extra dependencies, you can instead install `typer-slim`. - ```bash pip install typer ``` -...includes the same optional dependencies as: - -```bash -pip install "typer-slim[standard]" -``` - /// diff --git a/docs/tutorial/options-autocompletion.md b/docs/tutorial/options-autocompletion.md index 773a439e06..a68cb7986a 100644 --- a/docs/tutorial/options-autocompletion.md +++ b/docs/tutorial/options-autocompletion.md @@ -300,7 +300,7 @@ Using `stderr=True` tells **Rich** that the output should be shown in "standard /// info -If you can't install and use Rich, you can also use `print(lastname, file=sys.stderr)` or `typer.echo("some text", err=True)` instead. +If you have disabled Rich, you can also use `print(lastname, file=sys.stderr)` or `typer.echo("some text", err=True)` instead. /// diff --git a/docs/tutorial/options/help.md b/docs/tutorial/options/help.md index 509823815f..e6a5dbafa6 100644 --- a/docs/tutorial/options/help.md +++ b/docs/tutorial/options/help.md @@ -54,7 +54,7 @@ Options: The same as with *CLI arguments*, you can put the help for some *CLI options* in different panels to be shown with the `--help` option. -If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel you want for each *CLI option*: +Using Rich, you can set the `rich_help_panel` parameter to the name of the panel you want for each *CLI option*: {* docs_src/options/help/tutorial002_an_py39.py hl[15,21] *} diff --git a/docs/tutorial/package.md b/docs/tutorial/package.md index 617c93cd0b..e58256b428 100644 --- a/docs/tutorial/package.md +++ b/docs/tutorial/package.md @@ -681,12 +681,6 @@ You just have to pass it the module to import (`rick_portal_gun.main`) and it wi By specifying the `--name` of the program it will be able to use it while generating the docs. -/// tip - -If you installed `typer-slim` and don't have the `typer` command, you can use `python -m typer` instead. - -/// - ### Publish a new version with the docs Now you can publish a new version with the updated docs. diff --git a/docs/tutorial/printing.md b/docs/tutorial/printing.md index c4a1582f40..7c8c4dea69 100644 --- a/docs/tutorial/printing.md +++ b/docs/tutorial/printing.md @@ -112,7 +112,7 @@ In general, **Typer** tends to be the entry point to your program, taking the fi **Rich** is useful for the parts that need to *display* information. Showing beautiful content on the screen. -The best results for your command line application would be achieved combining both **Typer** and **Rich**. +The best results for your command line application are achieved combining both **Typer** and **Rich**. ## "Standard Output" and "Standard Error" diff --git a/docs/tutorial/progressbar.md b/docs/tutorial/progressbar.md index 57b1fbd57e..a74906957e 100644 --- a/docs/tutorial/progressbar.md +++ b/docs/tutorial/progressbar.md @@ -75,7 +75,7 @@ If you can use Rich, use the information above, the Rich docs, and skip the rest /// -But if you can't use Rich, Typer (actually Click) comes with a simple utility to show progress bars. +But if you can't use Rich and have it disabled, Typer (actually Click) comes with a simple utility to show progress bars. /// info diff --git a/docs/tutorial/prompt.md b/docs/tutorial/prompt.md index 4bb119fd17..cc00041067 100644 --- a/docs/tutorial/prompt.md +++ b/docs/tutorial/prompt.md @@ -75,7 +75,7 @@ Aborted! ## Prompt with Rich -If you installed Rich as described in [Printing and Colors](printing.md){.internal-link target=_blank}, you can use Rich to prompt the user for input: +You can use Rich to prompt the user for input: {* docs_src/prompt/tutorial004_py39.py hl[2,9] *} diff --git a/docs/tutorial/typer-command.md b/docs/tutorial/typer-command.md index 8f186c1855..ee07f1260d 100644 --- a/docs/tutorial/typer-command.md +++ b/docs/tutorial/typer-command.md @@ -18,13 +18,7 @@ pip install typer ...it includes the `typer` command. -If you don't want to have the `typer` command, you can install instead: - -```bash -pip install typer-slim -``` - -You can still use it by calling the Typer library as a module with: +If you don't want to use the `typer` command, you can call the Typer library as a module with: ```bash python -m typer @@ -261,7 +255,7 @@ $ typer some_script.py utils docs /// tip -If you installed only `typer-slim` and you don't have the `typer` command, you can still generate docs with: +If you don't want to use the `typer` command, you can still generate docs with: ```console $ python -m typer some_script.py utils docs diff --git a/pyproject.toml b/pyproject.toml index 61790b949e..95c21614dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,9 @@ sync-dependencies = [ [tool.tiangolo._internal-slim-build.packages.typer-slim.project] name = "typer-slim" +dependencies = [ + "typer", +] [tool.tiangolo._internal-slim-build.packages.typer] include-optional-dependencies = ["standard"] diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index 4c4d79dda7..2d56c2a41b 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -6,10 +6,7 @@ from typing import Optional, Union import click -from typer.core import HAS_SHELLINGHAM - -if HAS_SHELLINGHAM: - import shellingham +import shellingham class Shells(str, Enum): @@ -246,14 +243,11 @@ def _get_shell_name() -> Union[str, None]: returned. """ name: Union[str, None] # N.B. shellingham is untyped - if HAS_SHELLINGHAM: - try: - # N.B. detect_shell returns a tuple of (shell name, shell command). - # We only need the name. - name, _cmd = shellingham.detect_shell() # noqa: TID251 - except shellingham.ShellDetectionFailure: # pragma: no cover - name = None - else: - name = None # pragma: no cover + try: + # N.B. detect_shell returns a tuple of (shell name, shell command). + # We only need the name. + name, _cmd = shellingham.detect_shell() # noqa: TID251 + except shellingham.ShellDetectionFailure: # pragma: no cover + name = None return name diff --git a/typer/completion.py b/typer/completion.py index db87f83e3f..0d621e411d 100644 --- a/typer/completion.py +++ b/typer/completion.py @@ -7,7 +7,6 @@ from ._completion_classes import completion_init from ._completion_shared import Shells, _get_shell_name, get_completion_script, install -from .core import HAS_SHELLINGHAM from .models import ParamMeta from .params import Option from .utils import get_params_from_function @@ -18,7 +17,7 @@ def get_completion_inspect_parameters() -> tuple[ParamMeta, ParamMeta]: completion_init() test_disable_detection = os.getenv("_TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION") - if HAS_SHELLINGHAM and not test_disable_detection: + if not test_disable_detection: parameters = get_params_from_function(_install_completion_placeholder_function) else: parameters = get_params_from_function( diff --git a/typer/core.py b/typer/core.py index d0d888ccf0..3500090f64 100644 --- a/typer/core.py +++ b/typer/core.py @@ -1,5 +1,4 @@ import errno -import importlib.util import inspect import os import sys @@ -28,8 +27,7 @@ MarkupMode = Literal["markdown", "rich", None] MARKUP_MODE_KEY = "TYPER_RICH_MARKUP_MODE" -HAS_RICH = importlib.util.find_spec("rich") is not None -HAS_SHELLINGHAM = importlib.util.find_spec("shellingham") is not None +HAS_RICH = os.getenv("TYPER_USE_RICH", True) if HAS_RICH: DEFAULT_MARKUP_MODE: MarkupMode = "rich"