pre-commit by design operates on files, it also is optimized to batch runs of linters against files into multiple processes
what's happening here is your configuration is running several invocations (~1 per processor) of bash -c "cd bar && flake8" file1 file2 file3 etc. etc.
fortunately there's a setting you can use to fix this for you:
pass_filenames: false
with that:
---
repos:
- repo: local
hooks:
- id: flake8-foo
name: Run flake8 in foo package
entry: bash -c "cd foo && flake8"
language: python
pass_filenames: false
files: ^foo/
types: [python]
- id: flake8-bar
name: Run flake8 in bar package
entry: bash -c "cd bar && flake8"
language: python
pass_filenames: false
files: ^bar/
types: [python]
that said, you're losing most of the benefits of the framework by going to a repo: local hook:
- pre-commit isn't managing the installation of the tools (each of your developers has to install the tool separately and at a particular version)
- any filename-based optimizations aren't happening
- if you only change one file, you're currently linting your whole repository twice
- during merge conflicts, pre-commit optimizes which files to run (not the whole repo)
- and more
what I'd suggest instead for your monorepo setup is to still call flake8 in the normal way but utilize --config such that it works against your sub-repos:
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
name: flake8 ./foo/
alias: flake8-foo
files: ^foo/
args: [--config, foo/setup.cfg]
- id: flake8
name: flake8 ./bar/
alias: flake8-bar
files: ^bar/
args: [--config, bar/setup.cfg]
disclaimer: I'm the author of pre-commit and the current maintainer of flake8
Answer from anthony sottile on Stack OverflowFlake8
flake8.pycqa.org › en › latest › user › using-hooks.html
Using Version Control Hooks — flake8 7.3.0 documentation
The easiest way to get started is to add this configuration to your .pre-commit-config.yaml: - repo: https://github.com/pycqa/flake8 rev: '' # pick a git hash / tag to point to hooks: - id: flake8
Videos
Flake8
flake8.pycqa.org › en › 3.7.8 › user › using-hooks.html
Using Version Control Hooks — flake8 3.7.8 documentation
Flake8 can be included as a hook for pre-commit.
GitHub
github.com › pre-commit › pre-commit-hooks › issues › 430
pre-commit flake8 check fails with no error message · Issue #430 · pre-commit/pre-commit-hooks
December 17, 2019 - ~> cat .pre-commit-config.yaml repos: - repo: git@git.yelpcorp.com:mirrors/pre-commit/pre-commit-hooks rev: v2.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-docstring-first - id: check-executables-have-shebangs - id: check-merge-conflict - id: check-yaml - id: debug-statements - id: double-quote-string-fixer - id: flake8 - id: check-added-large-files - id: check-byte-order-marker - id: fix-encoding-pragma - id: requirements-txt-fixer ~> cat tox.ini | grep -A 3 flake8 [flake8] ignore = exclude = .git,.tox,docs,virtualenv_run filename = *.py (pre-commit)
Author drolando
GitHub
github.com › PyCQA › flake8 › blob › main › .pre-commit-config.yaml
flake8/.pre-commit-config.yaml at main · PyCQA/flake8
flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code. - flake8/.pre-commit-config.yaml at main · PyCQA/flake8
Author PyCQA
GitHub
github.com › pre-commit › pre-commit-hooks › issues › 311
How to use flake8 plugins with pre-commit · Issue #311 · pre-commit/pre-commit-hooks
August 8, 2018 - flake8 plugins are usually distributed through a standalone python package on PyPI, e.g. flake8-print flake8-docstring. In theory, I can locate where pre-commit's venv is and install plugin packages into that venv by myself, but it's really hacky and hard to be deterministically done for all other teammates and CI.
Author ushuz
Stack Overflow
stackoverflow.com › questions › 71189996 › correctly-using-pre-commit-with-flake8-plugins
pre commit.com - Correctly using pre-commit with flake8 plugins - Stack Overflow
Running it from local, the versions of the plugins are managed by poetry, and can be easily modified in pyproject.toml while locking ensures there are no unexpected version bumps happening, but there's seemingly no way to achieve this when specifying the plugins through additional_dependencies on the flake8 hook. If the versions are left unconstrained, pre-commit may use a different linting configuration in different environments, but then if an exact constraint is provided, it becomes increasingly more difficult to manage as the version bumps have to be done completely manually.
Flake8
flake8.pycqa.org › en › 3.9.0 › user › using-hooks.html
Using Version Control Hooks — flake8 3.9.0 documentation
Flake8 can be included as a hook for pre-commit.
Calmcode
calmcode.io › course › pre-commit › flake8-for-python
Calmcode - pre-commit: Flake8 for Python
The config file that contans flake8 which we use in the video is listed below. # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - id: check-ast - id: check-json - repo: https://gitlab.com/pycqa/flake8 rev: 8f9b4931b9a28896fb43edccb23016a7540f5b82 hooks: - id: flake8 ·
Flake8
flake8.pycqa.org › en › 3.2.1 › user › using-hooks.html
Using Version Control Hooks — flake8 3.2.1 documentation
Flake8 aims to make smart choices that keep things fast for users where possible. As a result, the Flake8 Git pre-commit will default to only checking files that have been staged (i.e., added to the index).
GitHub
github.com › peterjc › flake8-black › blob › master › .pre-commit-config.yaml
flake8-black/.pre-commit-config.yaml at master · peterjc/flake8-black
flake8 plugin to run black for checking Python coding style - flake8-black/.pre-commit-config.yaml at master · peterjc/flake8-black
Author peterjc
GitHub
github.com › pre-commit › pre-commit-hooks › issues › 112
flake8 ignores --config args · Issue #112 · pre-commit/pre-commit-hooks
April 29, 2016 - With the following config - id: flake8 args: ['--config=setup.cfg'] Any settings in setup.cfg are never read. Adding additional settings e.g. args: ['--config=setup.cfg', '--max-line-length=500'] will set max line length to 500 but will ...
Author dwaynebailey
MozillaWiki
wiki.mozilla.org › TestEngineering › Web › Automation › Flake8_Pre_Commit_Hook
TestEngineering/Web/Automation/Flake8 Pre Commit Hook
August 26, 2016 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Readthedocs
wemake-python-styleguide.readthedocs.io › en › 0.15.1 › pages › usage › integrations › plugins.html
Plugins and hooks — wemake-python-styleguide 0.15.1 documentation
Open <your_local_repo>/.git/hooks/pre-commit.sample (git runs this script after one calls git commit. If this script exits with code 1, commit would fail) Add the following code before the one checking for whitespace errors. # Your added code to run wemake-python-styleguide. Add this before # the whitespace error lines flake8 ...