Skip to content
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

Windows encoding bugfix #277

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions typer/_completion_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,19 @@ def install_powershell(*, prog_name: str, complete_var: str, shell: str) -> Path
if isinstance(result.stdout, str): # pragma: no cover
path_str = result.stdout
if isinstance(result.stdout, bytes):
try:
# PowerShell would be predominant in Windows
path_str = result.stdout.decode("windows-1252")
except UnicodeDecodeError: # pragma: no cover
path_obj = None
for encoding in ("windows-1252", "cp850", "utf8"):
try:
path_str = result.stdout.decode("utf8")
path_str = result.stdout.decode(encoding).strip()
if os.path.exists(path_str):
path_obj = Path(path_str.strip())
break
except UnicodeDecodeError:
click.echo("Couldn't decode the path automatically", err=True)
raise
pass
Comment on lines 193 to +194
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use contextlib.suppress there?

if path_obj is None:
click.echo("Couldn't decode the path automatically", err=True)
raise
svlandeg marked this conversation as resolved.
Show resolved Hide resolved

path_obj = Path(path_str.strip())
parent_dir: Path = path_obj.parent
parent_dir.mkdir(parents=True, exist_ok=True)
Expand Down
Loading