Skip to content

Commit

Permalink
Merge pull request #1474 from pre-commit/unicode_error_py_launcher
Browse files Browse the repository at this point in the history
avoid a UnicodeError on windows with non-charmap characters
  • Loading branch information
asottile authored May 27, 2020
2 parents 42562a1 + 0781dac commit d71699d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pre_commit/languages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def _find_by_py_launcher(
) -> Optional[str]: # pragma: no cover (windows only)
if version.startswith('python'):
num = version[len('python'):]
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
env = dict(os.environ, PYTHONIOENCODING='UTF-8')
try:
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
return cmd_output(*cmd)[1].strip()
return cmd_output(*cmd, env=env)[1].strip()
except CalledProcessError:
pass
return None
Expand Down

0 comments on commit d71699d

Please sign in to comment.