precommit: Ignore very large files

This commit is contained in:
Ole Schütt 2025-02-12 13:13:18 +01:00 committed by Ole Schütt
parent 0d7f5ab581
commit 2819de3bd6

View file

@ -124,11 +124,12 @@ def main() -> None:
continue
file_list += [os.path.join(root, fn) for fn in files]
# Filter symlinks, backup copies, logs, and hidden files.
# Filter symlinks, backup copies, logs, hidden, and very large files.
file_list = [fn for fn in file_list if not os.path.islink(fn)]
file_list = [fn for fn in file_list if not fn[-1] in ("~", "#")]
file_list = [fn for fn in file_list if not fn.endswith(".log")]
file_list = [fn for fn in file_list if not os.path.basename(fn).startswith(".")]
file_list = [fn for fn in file_list if os.path.getsize(fn) < 2**20] # 1MiB
# Sort files by size as larger ones will take longer to process.
file_list.sort(reverse=True, key=lambda fn: os.path.getsize(fn))