Skip to content

Only run pre-commit hooks on modified filesΒ #1175

Open
@johnnv1

Description

@johnnv1

Motivation

Improve integration with pre-commit

Expected behavior

Can use the nbdev_clear without having a nbdev config at settings.ini or to implicit pass args: ['-fname', 'mydir/'] at pre-commit config.

Explanation

As I explain here, seems to be a workaround need to add the path if you don't have a nbdev config. Mainly, because this will cause the command to be executed for all files at that path, which is unnecessary.

If the command accepts n arguments (multiple filenames), we can use the pre-commit "normally", by letting it command in which files the hook should be executed -- only those that have been changed in the commit.

Consequently, this will improve the hook's execution speed, since it will not be checking for unnecessary files.


With this enhancement, we can update the .pre-commit-hooks.yaml to:

--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -5,7 +5,8 @@
   always_run: true
-  pass_filenames: false
+  pass_filenames: true
+  types: [jupyter]

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions