pre-commit not picking files for pip-tools

160 views Asked by At

I've the following repo structure:

libs/
- l1/
 - pyproject.toml
- l2/
 - pyproject.toml

batch/
- b1/
 - pyproject.toml
- b2/
 - pyproject.toml

pipelines/
- p1/
 - pyproject.toml
- p2/
 - pyproject.toml

pyproject.toml

And the following pre-commit hook configured:

---
files: .(yaml|yml|py|toml)$
repos:
  - repo: https://github.com/jazzband/pip-tools
    rev: 7.3.0
    hooks:
      - id: pip-compile
        name: Run pip-compile for 'prod' env.
        args:
          - -o
          - pyproject.lock
          - --generate-hashes
          - --strip-extras

The problem is it only picks the repo root's pyproject.toml file. All the others are skipped? Why is that? I've tried using files options to no avail. What is the problem here?

1

There are 1 answers

4
anthony sottile On

there are two separate files configurations -- you've overridden the wrong one.

the files at the top level is the whole repository filter -- it's usually used to narrow down to a specific scope if you need it (and uncommon in most uses of pre-commit)

the files you are trying to overwrite comes originally from the hook itself (which sets files: ^requirements\.(in|txt)$) -- to override that you need to put your files inside the hook mapping:

repos:
  - repo: https://github.com/jazzband/pip-tools
    rev: 7.3.0
    hooks:
      - id: pip-compile
        name: Run pip-compile for 'prod' env.
        files: .*requirements*.txt|pyproject.toml$

disclaimer: I wrote pre-commit