|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import argparse |
| 4 | +from fnmatch import fnmatch |
4 | 5 | import math |
5 | 6 | import os |
6 | 7 | import subprocess |
@@ -34,12 +35,17 @@ def find_large_added_files( |
34 | 35 | filenames: Sequence[str], |
35 | 36 | maxkb: int, |
36 | 37 | *, |
| 38 | + exclude: list[str]|None = None, |
37 | 39 | enforce_all: bool = False, |
38 | 40 | ) -> int: |
39 | 41 | # Find all added files that are also in the list of files pre-commit tells |
40 | 42 | # us about |
41 | 43 | retv = 0 |
42 | | - filenames_filtered = set(filenames) |
| 44 | + exclude = [] if not exclude else exclude |
| 45 | + filenames_filtered = { |
| 46 | + fname for fname in filenames |
| 47 | + if not any(fnmatch(fname, pat) for pat in exclude) |
| 48 | + } |
43 | 49 | filter_lfs_files(filenames_filtered) |
44 | 50 |
|
45 | 51 | if not enforce_all: |
@@ -68,12 +74,17 @@ def main(argv: Sequence[str] | None = None) -> int: |
68 | 74 | '--maxkb', type=int, default=500, |
69 | 75 | help='Maximum allowable KB for added files', |
70 | 76 | ) |
| 77 | + parser.add_argument( |
| 78 | + '--exclude', type=str, default='', |
| 79 | + help="Comma-separated list of glob-style patterns to be excluded", |
| 80 | + ) |
71 | 81 | args = parser.parse_args(argv) |
72 | 82 |
|
73 | 83 | return find_large_added_files( |
74 | 84 | args.filenames, |
75 | 85 | args.maxkb, |
76 | 86 | enforce_all=args.enforce_all, |
| 87 | + exclude=args.exclude.split(',') |
77 | 88 | ) |
78 | 89 |
|
79 | 90 |
|
|
0 commit comments