-
-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for Click 8 while keeping compatibility with Click 7 (#317
- Loading branch information
Showing
40 changed files
with
1,343 additions
and
468 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
curl https://raw.githubusercontent.com/python/cpython/main/Lib/venv/scripts/common/Activate.ps1 -o Activate.ps1 |
This file contains 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
Empty file.
This file contains 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,29 @@ | ||
from typing import List | ||
|
||
import click | ||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
|
||
def shell_complete( | ||
ctx: click.Context, param: click.Parameter, incomplete: str | ||
) -> List[str]: | ||
return ["Jonny"] | ||
|
||
|
||
@app.command(context_settings={"auto_envvar_prefix": "TEST"}) | ||
def main( | ||
name: str = typer.Option("John", hidden=True), | ||
lastname: str = typer.Option("Doe", "/lastname", show_default="Mr. Doe"), | ||
age: int = typer.Option(lambda: 42, show_default=True), | ||
nickname: str = typer.Option("", shell_complete=shell_complete), | ||
): | ||
""" | ||
Say hello. | ||
""" | ||
typer.echo(f"Hello {name} {lastname}, it seems you have {age}, {nickname}") | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
Empty file.
This file contains 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,41 @@ | ||
import os | ||
import subprocess | ||
|
||
from typer.testing import CliRunner | ||
|
||
from tests.assets import compat_click7_8 as mod | ||
|
||
runner = CliRunner() | ||
|
||
|
||
def test_hidden_option(): | ||
result = runner.invoke(mod.app, ["--help"]) | ||
assert result.exit_code == 0 | ||
assert "Say hello" in result.output | ||
assert "--name" not in result.output | ||
assert "/lastname" in result.output | ||
assert "TEST_LASTNAME" in result.output | ||
assert "(dynamic)" in result.output | ||
|
||
|
||
def test_coverage_call(): | ||
result = runner.invoke(mod.app) | ||
assert result.exit_code == 0 | ||
assert "Hello John Doe, it seems you have 42" in result.output | ||
|
||
|
||
def test_completion(): | ||
result = subprocess.run( | ||
["coverage", "run", mod.__file__, " "], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
encoding="utf-8", | ||
env={ | ||
**os.environ, | ||
"_COMPAT_CLICK7_8.PY_COMPLETE": "complete_zsh", | ||
"_TYPER_COMPLETE_ARGS": "compat_click7_8.py --nickname ", | ||
"_TYPER_COMPLETE_TESTING": "True", | ||
}, | ||
) | ||
# TODO: when deprecating Click 7, remove second option | ||
assert "Jonny" in result.stdout or "_files" in result.stdout |
This file contains 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 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 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 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 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 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 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 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 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 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 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.
b972981
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://typer.tiangolo.com as production
🚀 Deployed on https://612c8f801b20fc6aebfda5e2--typertiangolo.netlify.app