mirror of
https://github.com/NVIDIA/TensorRT-LLM.git
synced 2026-01-13 22:18:36 +08:00
[None][chore] add precommit hook to remove redundant tab and white space (#8534)
Signed-off-by: Xin He (SW-GPU) <200704525+xinhe-nv@users.noreply.github.com>
This commit is contained in:
parent
910e6b9684
commit
b8b2c9efb4
@ -84,6 +84,11 @@ repos:
|
||||
files: ".*/auto_deploy/.*"
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: test lists format
|
||||
name: Check for tabs and multiple spaces in test_lists txt files
|
||||
entry: ./scripts/format_test_list.py
|
||||
language: script
|
||||
files: tests/integration/test_lists/.*\.txt$
|
||||
- id: DCO check
|
||||
name: Checks the commit message for a developer certificate of origin signature
|
||||
entry: ./scripts/dco_check.py
|
||||
|
||||
48
scripts/format_test_list.py
Executable file
48
scripts/format_test_list.py
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Normalize tabs and multiple spaces to single spaces in files."""
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def normalize_whitespace(content: str) -> str:
|
||||
"""Remove leading whitespace, replace tabs and multiple spaces with single spaces."""
|
||||
lines = content.splitlines(keepends=True)
|
||||
normalized_lines = []
|
||||
|
||||
for line in lines:
|
||||
# Remove leading whitespace and tabs
|
||||
line = line.lstrip(' \t')
|
||||
# Replace tabs with single space
|
||||
line = line.replace('\t', ' ')
|
||||
# Replace multiple spaces with single space
|
||||
line = re.sub(r' +', ' ', line)
|
||||
normalized_lines.append(line)
|
||||
|
||||
return ''.join(normalized_lines)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Normalize tabs and multiple spaces to single spaces')
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args()
|
||||
|
||||
retval = 0
|
||||
for filename in args.filenames:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
original_contents = f.read()
|
||||
|
||||
normalized_contents = normalize_whitespace(original_contents)
|
||||
|
||||
if original_contents != normalized_contents:
|
||||
print(f'Fixing {filename}')
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
f.write(normalized_contents)
|
||||
retval = 1
|
||||
|
||||
return retval
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
Loading…
Reference in New Issue
Block a user