@@ -79,6 +79,22 @@ def _copy_dir(src, dst, ignore=[]): # type: (str, str, List[str]) -> None
7979 _copy_dir_old (src , dst , ignore )
8080
8181
82+ def _validate_checksums (dist_info , dir ): # type: (str, str) -> None
83+ try :
84+ import installer .records
85+
86+ with open (os .path .join (dist_info , 'RECORD' ), 'r' ) as f :
87+ lines = [line .strip () for line in f ]
88+
89+ for record in installer .records .parse_record_file (lines ):
90+ with open (os .path .join (dir , record .path .as_posix ()), 'rb' ) as f :
91+ if not record .validate (f .read ()):
92+ raise InstallException ('Invalid checksum: {}' .format (record ))
93+ except ImportError :
94+ import warnings
95+ warnings .warn ("'installer' package missing, skipping checksum verification" , RuntimeWarning )
96+
97+
8298def _generate_entrypoint_scripts (file , dir ): # type: (str, str) -> None
8399 entrypoints = configparser .ConfigParser ()
84100 entrypoints .read (file )
@@ -130,6 +146,8 @@ def build(wheel, cache_dir, optimize=[0, 1, 2]): # type: (str, str, List[int])
130146 elif optimize :
131147 compileall .compile_dir (pkg_cache_dir )
132148
149+ _validate_checksums (dist_info , pkg_cache_dir )
150+
133151 if os .path .isfile (entrypoints_file ):
134152 _generate_entrypoint_scripts (entrypoints_file , scripts_cache_dir )
135153
@@ -138,8 +156,6 @@ def build(wheel, cache_dir, optimize=[0, 1, 2]): # type: (str, str, List[int])
138156 with open (os .path .join (cache_dir , 'metadata.pickle' ), 'wb' ) as f :
139157 pickle .dump (metadata , f )
140158
141- # TODO: verify checksums
142-
143159 # TODO: replace scripts shebang
144160 # TODO: validate platform/python tags to make sure it is compatible
145161
0 commit comments