6

I would like to use the exactly same version of flake8 in requirements.txt and in .pre-commit-config.yaml.

To avoid redundancy I would like to keep the version number of flake8 exactly once in my repo.

Can pre-commit.com read the version number of flake8 from requirements.txt?

guettli
  • 25,042
  • 81
  • 346
  • 663

1 Answers1

1

it cannot

pre-commit intentionally does not read from the repository under test as this makes caching intractable

you can read more in this issue and the many duplicate issues linked there

for me, I no longer include flake8, etc. in my requirements files as pre-commit replaces the need to install linters / code formatters elsewhere


disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • I know this seems like a closed issue on the part of the lib creator, but to be fair pre-commit doesn't really "replace" the need to install linters - eg. we run our checks on CI, where pre-commit does not make sense, and it should run regardless of what the user has installed on his local machine (eg. his precommit install is wrong/broken/bypassed). This means having versions on requirements.txt + config.yaml, which is painful to maintain (eg. having to manually update dependabot PRs) – Marcelo Aug 01 '22 at 20:37
  • pre-commit works great as a CI tool, so yes it does – anthony sottile Aug 02 '22 at 00:36