-
-
Notifications
You must be signed in to change notification settings - Fork 899
➖ Vendor Click and streamline Typer's functionality and code base #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
svlandeg
wants to merge
24
commits into
master
Choose a base branch
from
drop-click
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9e9f712
initial vendoring of Click into _click subdir
svlandeg 136821e
Merge branch 'master' into drop-click
svlandeg 8bde5b8
Merge branch 'master' into drop-click
svlandeg b5a53ef
Remove unused Click code (#1601)
svlandeg 7783f0a
Merge branch 'master' into drop-click
svlandeg 83c6f86
Merge Click and Typer functionality (#1680)
svlandeg 1855beb
Merge branch 'master' into upstream_drop_click
svlandeg 2c3394e
Merge branch 'drop-click' of https://github.com/tiangolo/typer into u…
svlandeg 98d7e40
Increase coverage (#1690)
svlandeg 8b5e25a
Merge branch 'master' into drop-click
svlandeg d410917
fix
svlandeg fcc2a2d
fix uv lock
svlandeg 34a0731
Bring feature branch up-to-date with `master` (#1773)
svlandeg 50d713a
Enable `ty` and resolve typing issues (#1770)
svlandeg 9c84486
fix "typo"
svlandeg 62d21fc
Merge branch 'master' into drop-click
svlandeg 1c936a9
update docs
svlandeg 431586c
🎨 Auto format
github-actions[bot] bb50511
📝 Tweak additional wording around Click vendoring
tiangolo b46de71
📝 Add docs section to explain Click vendoring and thanks to the Click…
tiangolo 958ccc5
Merge branch 'master' into drop-click
svlandeg 5ef6e42
📝 Tweak docs about dependencies
tiangolo efe0f22
Merge branch 'drop-click' of https://github.com/tiangolo/typer into d…
svlandeg d839ebc
Merge branch 'master' into drop-click
svlandeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Vendored Click | ||
|
|
||
| /// note | ||
|
|
||
| This is historical information, if you are just learning Typer from scratch, you don't need to read it. ☕️ | ||
|
|
||
| /// | ||
|
|
||
| Typer used to depend on [Click](https://click.palletsprojects.com/), a popular tool for building CLIs in Python, as an external dependency. | ||
|
|
||
| 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. | ||
|
|
||
| Note that some Click functionality will not be available anymore in the future, as we continue to improve and extend Typer's codebase. | ||
|
|
||
| ## Breaking Changes | ||
|
|
||
| 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. | ||
|
|
||
| The same way, it supported adding Click-specific types to override the default Typer ones. | ||
|
|
||
| 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. | ||
|
|
||
| ## Codebase Compatibility Improvements | ||
|
|
||
| Because Typer used to depend on Click, any new features or changes in newer Click versions could break compatibility in Typer. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Compatibility Improvements for Your Apps | ||
|
|
||
| The fact that Typer depended on Click caused an additional ongoing issue that could happen from time to time to user projects. | ||
|
|
||
| Many packages come with a CLI, some of them could use Click, some could use Typer. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Future Improvements | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Typer Changes | ||
|
|
||
| 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. | ||
|
|
||
| Then Typer will gradually introduce new features and improvements that have been planned for a while but were too difficult to implement before this. | ||
|
|
||
| ## User Focus | ||
|
|
||
| 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. | ||
|
|
||
| ## Thank You Click | ||
|
|
||
| Click has been the foundation building block of Typer and most CLI's in Python (through Typer or directly with Click). | ||
|
|
||
| We wouldn't be here without Click, and we are very grateful for all the work that the Click team has done. | ||
|
|
||
| Thank you Click! 🙇 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import time | ||
|
|
||
| import typer | ||
|
|
||
| app = typer.Typer() | ||
|
|
||
|
|
||
| @app.command() | ||
| def write_atomic( | ||
| config: typer.FileText = typer.Option(..., mode="w", atomic=True), | ||
| pause: float = typer.Option(0.3), | ||
| ) -> None: | ||
| config.write("atomic-content-1\n") | ||
| config.flush() | ||
| typer.echo("halfway") | ||
| time.sleep(pause) | ||
| config.write("atomic-content-2\n") | ||
| config.flush() | ||
| typer.echo("written atomically") | ||
|
|
||
|
|
||
| @app.command() | ||
| def write_atomic_binary( | ||
| config: typer.FileBinaryWrite = typer.Option(..., atomic=True, lazy=False), | ||
| ) -> None: | ||
| config.write(b"\x00\x01binary-atomic\n") | ||
| typer.echo("written binary atomically") | ||
|
|
||
|
|
||
| @app.command() | ||
| def api_atomic( | ||
| config: typer.FileText = typer.Option(..., mode="w", atomic=True, lazy=False), | ||
| ) -> None: | ||
| typer.echo(f"name={config.name}") | ||
| typer.echo(f"repr={repr(config)}") | ||
| with config as entered: | ||
| typer.echo(f"entered={entered is config}") | ||
| entered.write("atomic-api-done\n") | ||
|
|
||
|
|
||
| @app.command() | ||
| def invalid_atomic_append( | ||
| config: typer.FileText = typer.Option(..., mode="a", atomic=True, lazy=False), | ||
| ) -> None: | ||
| typer.echo(config.name) # pragma: no cover | ||
|
|
||
|
|
||
| @app.command() | ||
| def invalid_atomic_exclusive( | ||
| config: typer.FileText = typer.Option(..., mode="x", atomic=True, lazy=False), | ||
| ) -> None: | ||
| typer.echo(config.name) # pragma: no cover | ||
|
|
||
|
|
||
| @app.command() | ||
| def invalid_atomic_read( | ||
| config: typer.FileText = typer.Option(..., mode="r", atomic=True, lazy=False), | ||
| ) -> None: | ||
| typer.echo(config.name) # pragma: no cover | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.