Skip to content

Commit 1829d73

Browse files
svlandegpre-commit-ci-lite[bot]github-actions[bot]tiangolo
authored
➖ Vendor Click and streamline Typer's functionality and code base (#1774)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
1 parent 2d7a5be commit 1829d73

74 files changed

Lines changed: 10174 additions & 355 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CITATION.cff

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ abstract: >-
1818
Typer, build great CLIs. Easy to code. Based on Python type hints.
1919
keywords:
2020
- typer
21-
- click
21+
- cli
22+
- python
2223
license: MIT

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,20 @@ For a more complete example including more features, see the <a href="https://ty
352352

353353
## Dependencies
354354

355-
**Typer** stands on the shoulders of giants. It has three required dependencies:
355+
**Typer** requires only a few dependencies (most are tiny):
356356

357-
* [Click](https://click.palletsprojects.com/): a popular tool for building CLIs in Python. Typer is based on it.
358357
* [`rich`](https://rich.readthedocs.io/en/stable/index.html): to show nicely formatted errors automatically.
359358
* [`shellingham`](https://github.com/sarugaku/shellingham): to automatically detect the current shell when installing completion.
359+
* [`annotated-doc`](https://github.com/fastapi/annotated-doc): to generate documentation from Python type annotations.
360+
* [`colorama`](https://github.com/tartley/colorama) (only on Windows): for producing colored terminal text on Windows.
361+
362+
### Click code
363+
364+
Typer used to depend on [Click](https://click.palletsprojects.com/) as well, a popular tool for building CLIs in Python.
365+
366+
Since version 0.26.0, Typer has vendored Click (included Click's source code internally, instead of installing it as a third party package) and has unified the code interactions between Typer and the embedded Click source code for easier maintainability in the future.
367+
368+
Note that some Click functionality will not be available anymore in the future, as we continue to improve and extend Typer's codebase.
360369

361370
### `typer-slim`
362371

docs/alternatives.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ It uses decorators on top of functions to modify the actual value of those funct
7070

7171
It was built with some great ideas and design using the features available in the language at the time (Python 2.x).
7272

73-
/// tip | **Typer** uses it for
73+
/// tip | **Typer** builds on top of Click functionality
7474

75-
Everything. 🚀
75+
It has <abbr title="included Click's source code internally, instead of installing it as a third party package">vendored</abbr> Click version 8.3.1 and adds a layer on top of it.
7676

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.
77+
Typer aims to make the code simpler and easier to use, with autocompletion everywhere, etc, while still providing many of the powerful features of Click underneath.
7878

7979
As someone pointed out: <em>["Nice to see it is built on Click but adds the type stuff. Me gusta!"](https://twitter.com/fishnets88/status/1210126833745838080)</em>
8080

docs/features.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ Auto completion works when you create a package (installable with `pip`). Or whe
6363

6464
///
6565

66-
/// tip
67-
68-
**Typer**'s completion is implemented internally, it uses ideas and components from Click and ideas from `click-completion`, but it doesn't use `click-completion` and re-implements some of the relevant parts of Click.
69-
70-
Then it extends those ideas with features and bug fixes. For example, **Typer** programs also support modern versions of PowerShell (e.g. in Windows 10) among all the other shells.
71-
72-
///
73-
7466
## Tested
7567

7668
* 100% <abbr title="The amount of code that is automatically tested">test coverage</abbr>.

docs/index.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,20 @@ For a more complete example including more features, see the <a href="https://ty
360360

361361
## Dependencies
362362

363-
**Typer** stands on the shoulders of giants. It has three required dependencies:
363+
**Typer** requires only a few dependencies (most are tiny):
364364

365-
* [Click](https://click.palletsprojects.com/): a popular tool for building CLIs in Python. Typer is based on it.
366365
* [`rich`](https://rich.readthedocs.io/en/stable/index.html): to show nicely formatted errors automatically.
367366
* [`shellingham`](https://github.com/sarugaku/shellingham): to automatically detect the current shell when installing completion.
367+
* [`annotated-doc`](https://github.com/fastapi/annotated-doc): to generate documentation from Python type annotations.
368+
* [`colorama`](https://github.com/tartley/colorama) (only on Windows): for producing colored terminal text on Windows.
369+
370+
### Click code
371+
372+
Typer used to depend on [Click](https://click.palletsprojects.com/) as well, a popular tool for building CLIs in Python.
373+
374+
Since version 0.26.0, Typer has vendored Click (included Click's source code internally, instead of installing it as a third party package) and has unified the code interactions between Typer and the embedded Click source code for easier maintainability in the future.
375+
376+
Note that some Click functionality will not be available anymore in the future, as we continue to improve and extend Typer's codebase.
368377

369378
### `typer-slim`
370379

docs/tutorial/click.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Vendored Click
2+
3+
/// note
4+
5+
This is historical information, if you are just learning Typer from scratch, you don't need to read it. ☕️
6+
7+
///
8+
9+
Typer used to depend on [Click](https://click.palletsprojects.com/), a popular tool for building CLIs in Python, as an external dependency.
10+
11+
Since version 0.26.0, Typer has vendored Click (included Click's source code internally, instead of installing it as a third party package) and has unified the code interactions between Typer and the embedded Click source code for easier maintainability in the future.
12+
13+
Note that some Click functionality will not be available anymore in the future, as we continue to improve and extend Typer's codebase.
14+
15+
## Breaking Changes
16+
17+
Typer used to support extracting the internal Click app from a Typer app to use and modify it with any Click functionality. For example, to add Click-specific plug-ins.
18+
19+
The same way, it supported adding Click-specific types to override the default Typer ones.
20+
21+
Using Click directly was an edge case feature that was not commonly used, and it is no longer supported. If your app depended specifically on this, you will need to either migrate it to use plain Typer, or migrate it to use Click directly instead of Typer.
22+
23+
## Codebase Compatibility Improvements
24+
25+
Because Typer used to depend on Click, any new features or changes in newer Click versions could break compatibility in Typer.
26+
27+
The Click team has always been very helpful and supportive with Typer. But still, this dependency interaction would cause extra effort and burden for both the Typer team and the Click team.
28+
29+
Now that Typer continues evolving, starting from a fixed copy of Click's source code, any changes in Click's codebase will not affect Typer.
30+
31+
The Typer team will not need to make sure there are workarounds for changes in new versions of Click, and the Click team will not need to consider additional edge cases caused by Typer.
32+
33+
## Compatibility Improvements for Your Apps
34+
35+
The fact that Typer depended on Click caused an additional ongoing issue that could happen from time to time to user projects.
36+
37+
Many packages come with a CLI, some of them could use Click, some could use Typer.
38+
39+
Some of these packages could require a recent version of Click that Typer still didn't support, but as all these package dependencies would belong to the same project, there would be conflicts.
40+
41+
In these cases, the package that depended on the newer version of Click would require installing it, but the other package that used Typer would break. Or if there were version pins, some combinations of packages would not be installable together.
42+
43+
Across different versions of Click through time, there were many changes needed in Typer to make it all compatible with multiple versions of Click at the same time.
44+
45+
Now that Typer and Click are decoupled, a package could depend on a newer version of Click, while another package that uses Typer would continue working as normally, as that Typer version would bundle anything necessary from Click's source code to work.
46+
47+
## Future Improvements
48+
49+
Both the Click team and the Typer team have future improvements planned, not having to coordinate with each other for compatibility will simplify the work of both teams.
50+
51+
In some cases feature ideas could overlap, and could have caused incompatibilities. Now this won't be a problem as each team can focus on each project independently.
52+
53+
## Typer Changes
54+
55+
After vendoring Click, Typer will reduce, simplify and refactor parts of the vendored Click code that are not necessary for Typer, or that could be done in a different way to facilitate future improvements in Typer.
56+
57+
Then Typer will gradually introduce new features and improvements that have been planned for a while but were too difficult to implement before this.
58+
59+
## User Focus
60+
61+
These decisions are all carefully planned and based on real world use cases extracted from the official Typer developer survey, including the tradeoff between the potential breaking changes for some use cases and the planned future features and improvements that will be enabled.
62+
63+
## Thank You Click
64+
65+
Click has been the foundation building block of Typer and most CLI's in Python (through Typer or directly with Click).
66+
67+
We wouldn't be here without Click, and we are very grateful for all the work that the Click team has done.
68+
69+
Thank you Click! 🙇

docs/tutorial/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ First, make sure you create your [virtual environment](../virtual-environments.m
99
```console
1010
$ pip install typer
1111
---> 100%
12-
Successfully installed typer click shellingham rich
12+
Successfully installed typer shellingham rich
1313
```
1414

1515
</div>

docs/tutorial/package.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ $ uv add typer
6060
Using CPython 3.14.0 interpreter at: /location/of/python/
6161
Creating virtual environment at: .venv
6262

63-
Resolved 10 packages in 21ms
63+
Resolved 9 packages in 21ms
6464
Built rick-portal-gun @ file:/home/rick-portal-gun
6565
Prepared 1 package in 19ms
66-
Installed 10 packages in 34ms
67-
+ click==8.3.1
66+
Installed 9 packages in 34ms
6867
+ colorama==0.4.6
6968
+ markdown-it-py==4.0.0
7069
+ mdurl==0.1.2
@@ -568,7 +567,6 @@ Collecting rick-portal-gun
568567
Downloading rick_portal_gun-0.1.0-py3-none-any.whl.metadata (435 bytes)
569568
Requirement already satisfied: typer<0.13.0,>=0.12.3 in ./.local/lib/python3.10/site-packages (from rick-portal-gun==0.1.0) (0.12.3)
570569
Requirement already satisfied: typing-extensions>=3.7.4.3 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (4.11.0)
571-
Requirement already satisfied: click>=8.0.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (8.1.7)
572570
Requirement already satisfied: shellingham>=1.3.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (1.5.4)
573571
Requirement already satisfied: rich>=10.11.0 in ./.local/lib/python3.10/site-packages (from typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (13.7.1)
574572
Requirement already satisfied: pygments<3.0.0,>=2.13.0 in ./.local/lib/python3.10/site-packages (from rich>=10.11.0->typer<0.13.0,>=0.12.3->rick-portal-gun==0.1.0) (2.17.2)

docs/tutorial/printing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ And for the cases where you want to display data more beautifully, or more advan
196196

197197
### Why `typer.echo`
198198

199-
`typer.echo()` (which is actually just `click.echo()`) applies some checks to try and convert binary data to strings, and other similar things.
199+
`typer.echo()` applies some checks to try and convert binary data to strings, and other similar things.
200200

201201
But in most of the cases you wouldn't need it, as in modern Python strings (`str`) already support and use Unicode, and you would rarely deal with pure `bytes` that you want to print on the screen.
202202

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ nav:
146146
- tutorial/exceptions.md
147147
- tutorial/one-file-per-command.md
148148
- tutorial/typer-command.md
149+
- tutorial/click.md
149150
- "":
150151
- reference/index.md
151152
- reference/typer.md

0 commit comments

Comments
 (0)