-
-
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 18 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
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
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,122 @@ | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from . import atomic_write_example as mod | ||
|
|
||
|
|
||
| def test_atomic_write(tmp_path: Path) -> None: | ||
| original_content = "existing-content\n" | ||
| output_file = tmp_path / "atomic-write-target.txt" | ||
| output_file.write_text(original_content, encoding="utf-8") | ||
|
|
||
| process = subprocess.Popen( | ||
| [ | ||
| sys.executable, | ||
| "-m", | ||
| "coverage", | ||
| "run", | ||
| mod.__file__, | ||
| "write-atomic", | ||
| f"--config={output_file}", | ||
| ], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| text=True, | ||
| ) | ||
| assert process.stdout is not None | ||
|
|
||
| # Halfway of writing the file, check that the original content is still there | ||
| halfway_line = process.stdout.readline().strip() | ||
| assert halfway_line == "halfway" | ||
| assert output_file.read_text(encoding="utf-8") == original_content | ||
|
|
||
| # Only at the end, the full new content is visible | ||
| stdout, stderr = process.communicate(timeout=5) | ||
| assert process.returncode == 0, stderr | ||
| assert "written atomically" in stdout | ||
| assert ( | ||
| output_file.read_text(encoding="utf-8") | ||
| == "atomic-content-1\natomic-content-2\n" | ||
| ) | ||
|
|
||
|
|
||
| def test_atomic_binary_write(tmp_path: Path) -> None: | ||
| output_file = tmp_path / "atomic-binary.bin" | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| "-m", | ||
| "coverage", | ||
| "run", | ||
| mod.__file__, | ||
| "write-atomic-binary", | ||
| f"--config={output_file}", | ||
| ], | ||
| capture_output=True, | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| assert result.returncode == 0, result.stderr | ||
| assert "written binary atomically" in result.stdout | ||
| assert output_file.read_bytes() == b"\x00\x01binary-atomic\n" | ||
|
|
||
|
|
||
| def test_atomic_api(tmp_path: Path) -> None: | ||
| output_file = tmp_path / "atomic-api.txt" | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| "-m", | ||
| "coverage", | ||
| "run", | ||
| mod.__file__, | ||
| "api-atomic", | ||
| f"--config={output_file}", | ||
| ], | ||
| capture_output=True, | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| assert result.returncode == 0, result.stderr | ||
| assert f"name={output_file}" in result.stdout | ||
| assert "repr=<_io.TextIOWrapper" in result.stdout | ||
| assert "entered=True" in result.stdout | ||
| assert output_file.read_text(encoding="utf-8") == "atomic-api-done\n" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("command_name", "expected_message"), | ||
| [ | ||
| ("invalid-atomic-append", "Appending to an existing file is not supported"), | ||
| ("invalid-atomic-exclusive", "Use the `overwrite`-parameter instead."), | ||
| ("invalid-atomic-read", "Atomic writes only make sense with `w`-mode."), | ||
| ], | ||
| ) | ||
| def test_atomic_mode_invalid_options( | ||
| tmp_path: Path, command_name: str, expected_message: str | ||
| ) -> None: | ||
| output_file = tmp_path / "atomic-invalid-mode.txt" | ||
| output_file.write_text("existing-content\n", encoding="utf-8") | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| "-m", | ||
| "coverage", | ||
| "run", | ||
| mod.__file__, | ||
| command_name, | ||
| f"--config={output_file}", | ||
| ], | ||
| capture_output=True, | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| assert result.returncode != 0 | ||
| combined_output = f"{result.stdout}\n{result.stderr}" | ||
| assert expected_message in combined_output |
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.