@@ -70,13 +70,24 @@ def write_wheel_file(filename, contents):
70
70
def write_wheel (out_dir , * , name , version , tag , metadata , description , contents ):
71
71
wheel_name = f'{ name } -{ version } -{ tag } .whl'
72
72
dist_info = f'{ name } -{ version } .dist-info'
73
+ license_files = {}
74
+ filtered_metadata = []
75
+ for header , value in metadata :
76
+ if header == 'License-File' :
77
+ license_dest = f'{ dist_info } /licenses/{ value } '
78
+ if value in contents :
79
+ license_files [license_dest ] = contents [value ]
80
+ filtered_metadata .append ((header , value ))
81
+ filtered_metadata .append ((header , value ))
82
+
73
83
return write_wheel_file (os .path .join (out_dir , wheel_name ), {
74
84
** contents ,
85
+ ** license_files ,
75
86
f'{ dist_info } /METADATA' : make_message ([
76
87
('Metadata-Version' , '2.4' ),
77
88
('Name' , name ),
78
89
('Version' , version ),
79
- * metadata ,
90
+ * filtered_metadata ,
80
91
], description ),
81
92
f'{ dist_info } /WHEEL' : make_message ([
82
93
('Wheel-Version' , '1.0' ),
@@ -107,13 +118,53 @@ def write_ziglang_wheel(out_dir, *, version, platform, archive):
107
118
contents = {}
108
119
contents ['ziglang/__init__.py' ] = b''
109
120
121
+ license_files = {}
122
+
123
+ # The paths to these licenses MUST match both the actual files
124
+ # in the Zig source tarballs and the License-File entries listed
125
+ # below in the metadata. These are not prefixed with "ziglang/"
126
+ # since these are the actual paths in the Zig source tarballs.
127
+ license_paths = [
128
+ 'LICENSE' ,
129
+ 'lib/libc/glibc/LICENSES' ,
130
+ 'lib/libc/mingw/COPYING' ,
131
+ 'lib/libc/musl/COPYRIGHT' ,
132
+ 'lib/libc/wasi/LICENSE' ,
133
+ 'lib/libc/wasi/LICENSE-APACHE' ,
134
+ 'lib/libc/wasi/LICENSE-APACHE-LLVM' ,
135
+ 'lib/libc/wasi/LICENSE-MIT' ,
136
+ 'lib/libcxx/LICENSE.TXT' ,
137
+ 'lib/libcxxabi/LICENSE.TXT' ,
138
+ 'lib/libunwind/LICENSE.TXT'
139
+ ]
140
+
141
+ found_license_files = set ()
142
+
110
143
for entry_name , entry_mode , entry_data in iter_archive_contents (archive ):
111
144
entry_name = '/' .join (entry_name .split ('/' )[1 :])
112
145
if not entry_name :
113
146
continue
114
147
if entry_name .startswith ('doc/' ):
115
148
continue
116
149
150
+ # The license files and their paths MUST remain in sync with
151
+ # the paths in the official Zig tarballs and with the ones
152
+ # defined below in the metadata.
153
+ if any (entry_name == license_path for license_path in [
154
+ 'LICENSE' ,
155
+ 'lib/libc/glibc/LICENSES' ,
156
+ 'lib/libc/mingw/COPYING' ,
157
+ 'lib/libc/musl/COPYRIGHT' ,
158
+ 'lib/libc/wasi/LICENSE' ,
159
+ 'lib/libc/wasi/LICENSE-APACHE' ,
160
+ 'lib/libc/wasi/LICENSE-APACHE-LLVM' ,
161
+ 'lib/libc/wasi/LICENSE-MIT' ,
162
+ 'lib/libcxx/LICENSE.TXT' ,
163
+ 'lib/libcxxabi/LICENSE.TXT' ,
164
+ 'lib/libunwind/LICENSE.TXT'
165
+ ]):
166
+ license_contents [entry_name ] = entry_data
167
+
117
168
zip_info = ZipInfo (f'ziglang/{ entry_name } ' )
118
169
zip_info .external_attr = (entry_mode & 0xFFFF ) << 16
119
170
contents [zip_info ] = entry_data
@@ -131,13 +182,22 @@ def write_ziglang_wheel(out_dir, *, version, platform, archive):
131
182
with open ('README.pypi.md' ) as f :
132
183
description = f .read ()
133
184
185
+ dist_info = f'ziglang-{ version } .dist-info'
186
+ for license_path , license_data in license_files .items ():
187
+ contents [f"{ dist_info } /licenses/ziglang/{ license_path } " ] = license_data
188
+
134
189
return write_wheel (out_dir ,
135
190
name = 'ziglang' ,
136
191
version = version ,
137
192
tag = f'py3-none-{ platform } ' ,
138
193
metadata = [
139
194
('Summary' , 'Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.' ),
140
195
('Description-Content-Type' , "'text/markdown'; charset=UTF-8; variant=GFM" ),
196
+ # The license expression and the file paths MUST remain in sync
197
+ # with the paths in the official Zig tarballs and with the ones
198
+ # defined above in the contents. The difference is that these
199
+ # are prefixed with "ziglang/" to match the paths in the wheel
200
+ # for metadata compliance.
141
201
('License-Expression' , 'MIT' ),
142
202
('License-File' , 'LICENSE' ),
143
203
('License-File' , 'ziglang/lib/libc/glibc/LICENSES' ),
0 commit comments