Only include sub-directory files in pre-commit hook

Viewed 45

Trying to add nbqa hooks to a project, e.g.

      - id: nbqa-black
        name: nbqa-black
        entry: nbqa black
        language: system

however, I only want to run this hook on a directory for files such as:

./notebooks/certain_notebook_folder/a_notebook.ipynb ./notebooks/certain_notebook_folder/one_more_level/another_notebook.ipynb

I can get this to work for all ipynb files under notebooks like:

      - id: nbqa-black
        name: nbqa-black
        entry: nbqa black
        files: ^notebooks\/.*\.ipynb$
        language: system

(ignore neatness of using wildcards in regex)

I would therefore think that something like either of:

      - id: nbqa-black
        name: nbqa-black
        entry: nbqa black
        files: ^notebooks\/certain_notebook_folder\/.*\.ipynb$
        language: system

or

      - id: nbqa-black
        name: nbqa-black
        entry: nbqa black
        files: ^notebooks.*certain_notebook_folder.*\.ipynb$
        language: system

would work, but neither picks up any files. What have I overlooked?

0 Answers
Related