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

Running pre-commit with Python installed from Windows Store raises UnicodeDecodeError #1358

Closed
Guts opened this issue Mar 10, 2020 · 5 comments · Fixed by #1359
Closed

Running pre-commit with Python installed from Windows Store raises UnicodeDecodeError #1358

Guts opened this issue Mar 10, 2020 · 5 comments · Fixed by #1359

Comments

@Guts
Copy link

Guts commented Mar 10, 2020

I think it's a special use case and maybe related to the known issues of this kind of installation, but still interesting to track it in issues isn't?

And the kind of error surprised me: UnicodeDecodeError.

Reproduce

  1. Install Python through Windows Store
  2. Create a virtualenv
  3. Install pre-commit and run the hooks

Environment

Trace

[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\username/.cache\pre-commit\patch1583836330.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/python/black.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Restored changes from C:\Users\username/.cache\pre-commit\patch1583836330.
Traceback (most recent call last):
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 54, in error_handler
    yield
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\main.py", line 371, in main
    return run(args.config, store, args)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\commands\run.py", line 337, in run
    install_hook_envs(hooks, store)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\repository.py", line 200, in install_hook_envs
    _hook_install(hook)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\repository.py", line 83, in _hook_install
    hook.prefix, hook.language_version, hook.additional_dependencies,
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\languages\python.py", line 192, in install_environment
    _make_venv(env_dir, python)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\languages\python.py", line 204, in make_venv
    cmd_output_b(*cmd, env=env, cwd='/')
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\util.py", line 140, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: <exception str() failed>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\username\doculents\git\test-project\.venv\Scripts\pre-commit.exe\__main__.py", line 7, in <module>
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\main.py", line 384, in main
    f'Command {args.command} failed to exit with a returncode',
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 62, in error_handler
    _log_and_exit(msg, e, traceback.format_exc())
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\error_handler.py", line 18, in _log_and_exit
    error_msg = f'{msg}: {type(exc).__name__}: {exc}'
  File "d:\username\doculents\git\test-project\.venv\lib\site-packages\pre_commit\util.py", line 115, in __str__
    return self.__bytes__().decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 341: invalid continuation byte
@asottile
Copy link
Member

hmm yes, I do believe that virtualenv is incompatible with windows store python in one way or another -- that said it should produce the error message instead

it might also be related to your username (does it contain an è?

either way there's two bugs here:

  1. the error handling code should handle arbitrary bytes (it used to, but I believe regressed in pre-commit 2.x)
  2. an upstream bug in virtualenv

@asottile
Copy link
Member

this is the underlying error fwiw:

    OSError: [WinError 1920] The file cannot be accessed by the system: 'C:\\Users\\IEUser\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe'

@asottile
Copy link
Member

here's the upstream issue for virtualenv: pypa/virtualenv#1709

@asottile
Copy link
Member

this has been released as part of 2.2.0 -- thanks again for the issue!

@Guts
Copy link
Author

Guts commented Mar 14, 2020

Thanks for the quick fix and release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants