Home > Enterprise >  How do I exclude multiple folders and/or file-patterns from pre-commit analysis?
How do I exclude multiple folders and/or file-patterns from pre-commit analysis?

Time:01-21

I have my python project. I'm trying to setup pre-commit checks using pre-commit. I want to exclude some folders and some files (by pattern) from the analysis. The `exclude tag in config file only supports string not an array.

E.g. in following project structure, I want to exclude poc and tests folders and conftest.py file.

root
├── poetry.lock
├── pyproject.toml
├── resources
├── src
│   ├── mylib
│   │   └── functions.py
│   └── poc
│       └── some_junk.py
├── conftest.py
└── tests
    ├── entry_point.py
    └── test_functions.py

I can exclude a folder or file using exclude tag, e.g. to exclude poc I do this:

exclude: poc

repos:
  - repo: https://github.com/pycqa/isort
    rev: 5.11.4
    hooks:
      - id: isort
      - id: ...

... but how do I exclude multiple files and folders?

CodePudding user response:

as documented exclude is a regular expression as such you can utilize | to exclude multiple things

the example given from the docs:

    -   id: my-hook
        exclude: |
            (?x)^(
                path/to/file1.py|
                path/to/file2.py|
                path/to/file3.py
            )$

disclaimer: I wrote pre-commit

  • Related