11from __future__ import annotations
22
33import dataclasses
4- import glob
54import os
65import shutil
76import sys
@@ -146,6 +145,16 @@ def _build_wheel_impl(
146145 else :
147146 install_dir = wheel_dirs ["platlib" ] / settings .wheel .install_dir
148147
148+ license_files = {
149+ x : x .read_bytes ()
150+ for y in settings .wheel .license_files
151+ for x in Path ().glob (y )
152+ }
153+ if settings .wheel .license_files and not license_files :
154+ logger .warning (
155+ "No license files found, set wheel.license-files to [] to suppress this warning"
156+ )
157+
149158 config = CMaker (
150159 cmake ,
151160 source_dir = Path (settings .cmake .source_dir or "." ),
@@ -162,12 +171,19 @@ def _build_wheel_impl(
162171 if metadata_directory is None :
163172 msg = "metadata_directory must be specified if wheel_directory is None"
164173 raise AssertionError (msg )
165- wheel = WheelWriter (metadata , Path (metadata_directory ), tags .as_tags_set ())
174+ wheel = WheelWriter (
175+ metadata ,
176+ Path (metadata_directory ),
177+ tags .as_tags_set (),
178+ license_files = license_files ,
179+ )
166180 dist_info_contents = wheel .dist_info_contents ()
167181 dist_info = Path (metadata_directory ) / f"{ wheel .name_ver } .dist-info"
168182 dist_info .mkdir (parents = True )
169183 for key , data in dist_info_contents .items ():
170184 path = dist_info / key
185+ if not path .parent .is_dir ():
186+ path .parent .mkdir (exist_ok = True , parents = True )
171187 path .write_bytes (data )
172188 return WheelImplReturn (wheel_filename = dist_info .name )
173189
@@ -215,22 +231,13 @@ def _build_wheel_impl(
215231
216232 process_script_dir (wheel_dirs ["scripts" ])
217233
218- license_files = [
219- Path (x )
220- for y in settings .wheel .license_files
221- for x in glob .glob (y , recursive = True )
222- ]
223- if settings .wheel .license_files and not license_files :
224- logger .warning (
225- "No license files found, set wheel.license-files to [] to suppress this warning"
226- )
227-
228- with WheelWriter (metadata , Path (wheel_directory ), tags .as_tags_set ()) as wheel :
234+ with WheelWriter (
235+ metadata ,
236+ Path (wheel_directory ),
237+ tags .as_tags_set (),
238+ license_files = license_files ,
239+ ) as wheel :
229240 wheel .build (wheel_dirs )
230- for license_file in license_files :
231- wheel .write (
232- str (license_file ), f"{ wheel .dist_info } /licenses/{ license_file .name } "
233- )
234241
235242 if editable :
236243 modules = {
0 commit comments