csachs / pyproject-flake8

pyproject-flake8 (pflake8), a monkey patching wrapper to connect flake8 with pyproject.toml configuration
The Unlicense
174 stars 16 forks source link

Pre-commit hook and pyproject-flake8 #3

Closed MartinGrignard closed 3 years ago

MartinGrignard commented 3 years ago

Hi :slightly_smiling_face:

Thanks for this nice addition to the flake8 ecosystem! I'm currently working on a project relying on pre-commit-config.yaml to insure consistency in the code style.

Since the default commit hook does not include your package, I tried using the method described here:

repos:
    # Flake8
    - repo: https://github.com/pycqa/flake8
      rev: 3.9.2
      hooks:
        - id: flake8
          additional_dependencies: [pyproject-flake8]

My config for flake8 in pyproject.toml is:

[tool.flake8]
ignore = "E203, E266, E501, W503, F403, F401"
exclude = ".git, .mypy_cache, .pytest_cache, build, dist"
max-line-length = 89
max-complexity = 18
select = "B,C,E,F,W,T4,B9"

Yet, when running the commit hook, I get:

E501 line too long (87 > 79 characters)

This means that the configuration is not parsed properly from the pyproject.toml. Do you have any idea to solve this?

Thanks :slightly_smiling_face:

MartinGrignard commented 3 years ago

Sorry for the auto-reply, but if someone comes across the same issue, here is a configuration that works. The problem was that the hook used the flake8 command and not pflake8:

- repo: https://github.com/pycqa/flake8
      rev: 3.9.2
      hooks:
        - id: flake8
          entry: pflake8
          additional_dependencies: [pyproject-flake8]
csachs commented 3 years ago

Indeed someone else may need such a clarification, I'll see if I'll add a section to the README how to use pflake8 with pre-commit.

MartinGrignard commented 3 years ago

I just saw that the repository includes a pre-commit hook so my solution might not be the recommended one. Thanks :slightly_smiling_face:

5yutan5 commented 3 years ago

Thank you @MartinGrignard. I was having the same problem. I don't know whether this clarification should be added to REDME, but I needed it.

tueda commented 2 years ago

I just saw that the repository includes a pre-commit hook so my solution might not be the recommended one. Thanks 🙂

I still like the above configuration because the version of flake8 is explicitly fixed (while the pre-commit hook in the repository does not specify the version of flake8; probably the latest one will be used, which potentially leads to some incompatibility in future).

jgz commented 1 year ago

Probably obvious to most,  but something I just ran into after setting this up on a new project.

If you're using vscode in WSL and you get the error saying it cant find pflake8 when you do a commit, then  you need to start vscode from inside your poetry venv.