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: Pre-Commit: Codespell/Clang-Format don't find Python executable #10940

Closed
JoergAtGithub opened this issue Oct 5, 2022 · 7 comments
Closed
Labels

Comments

@JoergAtGithub
Copy link
Member

Bug Description

I had partially success to get pre-commit to work on Windows.

Only codespell fails to find the Python executable. I tried already to add it to PATH, but it doesn't solve the issue:

fix utf-8 byte order marker..............................................Passed
check for case conflicts.................................................Passed
check json...........................................(no files to check)Skipped
check for merge conflicts................................................Passed
check xml............................................(no files to check)Skipped
check yaml...........................................(no files to check)Skipped
mixed line ending........................................................Passed
don't commit to branch...................................................Passed
codespell................................................................Failed
- hook id: codespell
- exit code: 9009

Python konnte nicht gefunden werden. Führen Sie die Verknüpfung ohne Argumente aus, um sie über den Microsoft Store zu installieren, oder deaktivieren Sie diese Verknüpfung unter

black................................................(no files to check)Skipped

Version

Main

OS

Windows 11 x64

@Holzhaus
Copy link
Member

Holzhaus commented Oct 5, 2022

That is really strange because the other hooks also use python.

@Holzhaus
Copy link
Member

Holzhaus commented Oct 5, 2022

You do have Python 3 installed, right? If so, I suggest you file an issue upstream: https://github.com/pre-commit/pre-commit/issues/new/choose

@JoergAtGithub
Copy link
Member Author

pre-commit/pre-commit#2545

The bug report was closed with the comment: "the bug is in your tools/codespell.py"

@JoergAtGithub
Copy link
Member Author

Also clang-format fails (was not triggered by my original code change). I guess that all the checks with a python script under ./tools/ fail.

@JoergAtGithub
Copy link
Member Author

My .git\hooks\pre-commit contains the correct path of the python interpreter:

#!/bin/sh
#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

# start templated
INSTALL_PYTHON='C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe'
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated

HERE="$(cd "$(dirname "$0")" && pwd)"
ARGS+=(--hook-dir "$HERE" -- "$@")

if [ -x "$INSTALL_PYTHON" ]; then
    exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
    exec pre-commit "${ARGS[@]}"
else
    echo '`pre-commit` not found.  Did you forget to activate your virtualenv?' 1>&2
    exit 1
fi

and it's Python version 3.9.7:

C:\>"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe"
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

@JoergAtGithub JoergAtGithub changed the title Pre-Commit: Codespell doesn't find Python executable Windows: Pre-Commit: Codespell/Clang-Format don't find Python executable Oct 7, 2022
@JoergAtGithub
Copy link
Member Author

For experiment I replaced the first shebang line of tools/clang_format.py
by
#!'C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python.exe'

Than clang format starts to work, but fails with executing a subprocess:

clang-format.............................................................Failed
- hook id: clang-format
- exit code: 1

[INFO] First pass: Reformatting added/changed lines...
[INFO] Second pass: Breaking long added/changed lines...
Traceback (most recent call last):
  File "C:\Users\Joerg.WORLDWARTWEB\source\repos\JoergAtGithub\mixxx\tools\clang_format.py", line 144, in <module>
    sys.exit(main())
  File "C:\Users\Joerg.WORLDWARTWEB\source\repos\JoergAtGithub\mixxx\tools\clang_format.py", line 131, in main
    config = get_clang_format_config_with_columnlimit(rootdir, BREAK_BEFORE)
  File "C:\Users\Joerg.WORLDWARTWEB\source\repos\JoergAtGithub\mixxx\tools\clang_format.py", line 25, in get_clang_format_config_with_columnlimit
    proc = subprocess.run(
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

black....................................................................Passed

@daschuer
Copy link
Member

Fixed by #11004

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

Successfully merging a pull request may close this issue.

3 participants