tom*_*omm 1 python git pre-commit pre-commit.com
我正在尝试将 flakehell 作为预提交钩子运行。
我的 .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: flakehell
name: flakehell
entry: flakehell lint project/
language: python
pass_filenames: true
stages: [push, commit]
verbose: true
Run Code Online (Sandbox Code Playgroud)
pyproject.toml:
[tool.flakehell]
exclude = ["README.md"]
format = "colored"
show_source = true
[tool.flakehell.plugins]
flake8-bandit = ["+*", "-S322"]
flake8-bugbear = ["+*"]
flake8-builtins = ["+*"]
flake8-comprehensions = ["+*"]
flake8-darglint = ["+*"]
flake8-docstrings = ["+*"]
flake8-eradicate = ["+*"]
flake8-isort = ["+*"]
flake8-mutable = ["+*"]
flake8-pytest-style = ["+*"]
flake8-spellcheck = ["+*"]
mccabe = ["+*"]
pep8-naming = ["+*"]
pycodestyle = ["+*"]
pyflakes = ["+*"]
pylint = ["+*"]
Run Code Online (Sandbox Code Playgroud)
还是有些问题。当我尝试使用 git commit 时,我看到 flakehell 开始工作了。几秒钟后它失败了,我得到了错误:
“UnicodeDecodeError:‘utf-8’编解码器无法解码位置 10 中的字节 0xb8:起始字节无效”
没有“预提交”它工作得很好(我的意思是当我只输入“flakehell lint”时)
甚至可以将 flakehell 配置为预提交吗?
如果没有 - 您是否为 python 项目推荐任何更好/有效的解决方案?
你的配置不正确,你已经不局限于传递给你的钩子与这两个文件files
或types
因此被默认为所有的文件在你的仓库。大概你有一些正在传递给 flakehell 的二进制文件
我还注意到您的配置同时传递了路径和具有pass_filenames: true
(pass_filenames: true
是默认值,因此您不应使用它)
你要么想在 args 中列出路径(不推荐,因为你总是比你改变的要多)或者你想正确过滤文件名
此外,verbose: true
不打算在调试之外使用,因为它会向输出添加警告噪声
此外,您不是通过预提交来管理 flakehell 的安装,这会给您的贡献者增加额外的负担来尝试在本地设置任何开发环境,预提交的大部分要点是它管理安装您的工具,以便您贡献者不必跳过箍来获得正确的格式/linting 设置(消除一整类“它在我的机器上工作”的问题)
另外,看起来 flakehell 直接支持预提交,所以你不需要repo: local
像你做的那样使用逃生舱口
把所有这些放在一起,你可能想要这样的东西:
repos:
- repo: https://github.com/life4/flakehell
rev: v.0.7.1
hooks:
- id: flakehell
Run Code Online (Sandbox Code Playgroud)
如果您想使用本地配置,您可能需要以下内容:
repos:
- repo: local
hooks:
- id: flakehell
name: flakehell
entry: flakehell lint
types: [python]
files: ^project/
language: python
additional_dependencies: [flakehell==0.7.1]
stages: [push, commit]
Run Code Online (Sandbox Code Playgroud)
免责声明:我是 pre-commit 的创建者