Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

python - Flakehell with .toml configuration and pre-commit hook

I'm trying to run flakehell as pre-commit hook.

my .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

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 = ["+*"]

Still have some problems. When I try to use git commit I see that flakehell started working. After a few seconds it fails and I got the error:

"UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position 10: invalid start byte"

Without "pre-commit" it works great (I mean when I just type "flakehell lint")

Is it even possible to configure flakehell as pre-commit?

If not - do you recommend any better/working solution for python projects?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

your configuration is incorrect, you haven't limited the files that are passed to your hook with either files or types so it is defaulting to all files in your repository. presumably you have some binary file which is being passed to flakehell

I also notice that your configuration passes both a path and has pass_filenames: true (pass_filenames: true is the default so you shouldn't use that)

you either want to list paths in args (not recommended since you always lint more than what you're changing) or you want to filter the filenames properly

additionally, verbose: true is not intended for use outside of debugging as it adds warning noise to the output

additionally, you're not managing the installation of flakehell through pre-commit which will add additional burden to your contributors to try and set up whatever development environment locally, most of the point of pre-commit is that it manages installing your tools so your contributors don't have to jump through hoops to have the correct formatting / linting setup (eliminating a whole class of "it works on my machine" problems)

additionally, it looks like flakehell has direct support for pre-commit, so you don't need to use the repo: local escape hatch as you're doing

putting all of that together, you probably want something like this:

repos:
-   repo: https://github.com/life4/flakehell
    rev: v.0.7.1
    hooks:
    -   id: flakehell

if you want to go with your local configuration you probably want something like:

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]

disclaimer: I'm the creator of pre-commit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...