1
1
import os
2
+ import sys
2
3
import zipfile
3
4
4
- MAX_SIZE_MB = 250
5
+ # Read the VLLM_MAX_SIZE_MB environment variable, defaulting to 250 MB
6
+ VLLM_MAX_SIZE_MB = int (os .environ .get ('VLLM_MAX_SIZE_MB' , 250 ))
5
7
6
8
7
9
def print_top_10_largest_files (zip_file ):
10
+ """Print the top 10 largest files in the given zip file."""
8
11
with zipfile .ZipFile (zip_file , 'r' ) as z :
9
12
file_sizes = [(f , z .getinfo (f ).file_size ) for f in z .namelist ()]
10
13
file_sizes .sort (key = lambda x : x [1 ], reverse = True )
11
14
for f , size in file_sizes [:10 ]:
12
- print (f"{ f } : { size / (1024 * 1024 )} MBs uncompressed." )
15
+ print (f"{ f } : { size / (1024 * 1024 ):.2f } MBs uncompressed." )
13
16
14
17
15
18
def check_wheel_size (directory ):
19
+ """Check the size of .whl files in the given directory."""
16
20
for root , _ , files in os .walk (directory ):
17
- for f in files :
18
- if f .endswith (".whl" ):
19
- wheel_path = os .path .join (root , f )
20
- wheel_size = os .path .getsize (wheel_path )
21
- wheel_size_mb = wheel_size / (1024 * 1024 )
22
- if wheel_size_mb > MAX_SIZE_MB :
23
- print (
24
- f"Wheel { wheel_path } is too large ({ wheel_size_mb } MB) "
25
- f"compare to the allowed size ({ MAX_SIZE_MB } MB)." )
21
+ for file_name in files :
22
+ if file_name .endswith (".whl" ):
23
+ wheel_path = os .path .join (root , file_name )
24
+ wheel_size_mb = os .path .getsize (wheel_path ) / (1024 * 1024 )
25
+ if wheel_size_mb > VLLM_MAX_SIZE_MB :
26
+ print (f"Not allowed: Wheel { wheel_path } is larger "
27
+ f"({ wheel_size_mb :.2f} MB) than the limit "
28
+ f"({ VLLM_MAX_SIZE_MB } MB)." )
26
29
print_top_10_largest_files (wheel_path )
27
30
return 1
28
31
else :
29
32
print (f"Wheel { wheel_path } is within the allowed size "
30
- f"({ wheel_size_mb } MB)." )
33
+ f"({ wheel_size_mb :.2f } MB)." )
31
34
return 0
32
35
33
36
34
37
if __name__ == "__main__" :
35
- import sys
36
- sys .exit (check_wheel_size (sys .argv [1 ]))
38
+ if len (sys .argv ) < 2 :
39
+ print ("Usage: python check-wheel-size.py <directory>" )
40
+ sys .exit (1 )
41
+
42
+ directory = sys .argv [1 ]
43
+ sys .exit (check_wheel_size (directory ))
0 commit comments