question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre-commit hook and pyproject-flake8

See original GitHub issue

Hi 🙂

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 🙂

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
MartinGrignardcommented, Jun 18, 2021

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]
0reactions
tuedacommented, Feb 16, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Version Control Hooks — flake8 6.0.0 documentation
pre -commit creates an isolated environment for hooks. To use flake8 plugins, use the additional_dependencies setting. - id ...
Read more >
How to setup your project with pre-commit, black, and flake8
Several OpenStax Python projects use Git hooks via pre-commit in order to run formatting and linting checks before the commit process.
Read more >
Automate Python workflow using pre-commits: black and flake8
Good thing, I learned about Git hooks, specifically pre-commit hooks. It enables you to automatically run a short script before commit ting.
Read more >
Pre-commit flake8 with setup.cfg in subfolder - Stack Overflow
Root folder has two packages · Each has its own. pyproject.toml (configures black and isort ); setup.cfg (configures flake8 and pydocstyle ).
Read more >
Supported hooks - pre-commit
cheetah-reorder-imports - This hook reorders imports in cheetah files. cheetah-flake - Lint cheetah code using flake8 and some other checks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found