File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,11 @@ repos:
23
23
entry : python3 -m mypy --ignore-missing-imports
24
24
language : system
25
25
types : [python]
26
- files : ^litellm/
26
+ files : ^litellm/
27
+ # - id: check-file-length
28
+ # name: Check file length
29
+ # entry: python check_file_length.py
30
+ # args: ["10000"] # set your desired maximum number of lines
31
+ # language: python
32
+ # files: litellm/.*\.py
33
+ # exclude: ^litellm/tests/
Original file line number Diff line number Diff line change
1
+ import sys
2
+
3
+
4
+ def check_file_length (max_lines , filenames ):
5
+ bad_files = []
6
+ for filename in filenames :
7
+ with open (filename , "r" ) as file :
8
+ lines = file .readlines ()
9
+ if len (lines ) > max_lines :
10
+ bad_files .append ((filename , len (lines )))
11
+ return bad_files
12
+
13
+
14
+ if __name__ == "__main__" :
15
+ max_lines = int (sys .argv [1 ])
16
+ filenames = sys .argv [2 :]
17
+
18
+ bad_files = check_file_length (max_lines , filenames )
19
+ if bad_files :
20
+ bad_files .sort (
21
+ key = lambda x : x [1 ], reverse = True
22
+ ) # Sort files by length in descending order
23
+ for filename , length in bad_files :
24
+ print (f"{ filename } : { length } lines" )
25
+
26
+ sys .exit (1 )
27
+ else :
28
+ sys .exit (0 )
You can’t perform that action at this time.
0 commit comments