1
resposta

Flake8 com git hooks não funciona

Olá professor, depois de horas tentando configurar o flake8 para funcionar com o git hooks acabei desistindo.

o erro: "fatal: cannot run .git/hooks/pre-commit: No such file or directory"

o arquivo pre-commit existia e quando eu executava python3 .git/hooks/pre-commit funcionava perfeitamente, mas ele dava aquele erro sempre que eu tentava commitar

depois instalei o pre-commit pelo pip e segui estas instruções aqui: https://pre-commit.com/#pre-commit-configyaml---hooks

mas ainda assim não consegui, recebia este erro: An unexpected error has occurred: ExecutableNotFoundError: Executable "/home/sora/Documents/Courses not found Check the log at /home/sora/.cache/pre-commit/pre-commit.log"

o log é este:

error information

An unexpected error has occurred: ExecutableNotFoundError: Executable `/home/sora/Documents/Courses` not found

` Traceback (most recent call last): File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/error_handler.py", line 56, in error_handler yield File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/main.py", line 372, in main args=args.rest[1:], File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/commands/hook_impl.py", line 210, in hook_impl retv, stdin = runlegacy(hook_type, hook_dir, args) File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/commands/hook_impl.py", line 42, in runlegacy cmd = normalize_cmd((legacy_hook, *args)) File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/parse_shebang.py", line 82, in normalize_cmd exe = normexe(cmd[0]) File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/pre_commit/parse_shebang.py", line 61, in normexe error('not found') File "/home/sora/Documents/CoursesProjects/Alura/Python/PEP-8/venv/lib/python3.7/site-packages/precommit/parse_shebang.py", line 51, in error raise ExecutableNotFoundError(f'Executable {orig} {msg}') precommit.parse_shebang.ExecutableNotFoundError: Executable /home/sora/Documents/Courses not found

Tente de tudo, até resetei o repositório e também meu ambiente virtual, mas de nada adiantou

1 resposta

Oii Victor, tudo bem?

O log não está encontrando o arquivo pre-commit.

Você fez estes os passos abaixo para habilitar o bloqueio dos commits?

flake8 --install-hook=git

git config --bool flake8.strict true

Em caso positivo, se você utilizar o windows, vale conferir se no arquivo pre-commit o caminho do .exe do Python na primeira linha está correto e caso utilize linux, também verifique o caminho. Exemplo do arquivo pre-commit no windows:

#!c:\users\nadia\appdata\local\programs\python\python38-32\python.exe
import sys

from flake8.main import git

if __name__ == '__main__':
    sys.exit(
        git.hook(
            strict=git.config_for('strict'),
            lazy=git.config_for('lazy'),
        )
    )

Caso ainda não funcione, recomendo que faça um repositório de teste do git apenas localmente e tente habilitar o hook nele por meio dos comandos mostrados acima.

Fico no aguardo.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software