Skip to content

Commit f283e6b

Browse files
committed
windows: annotate license metadata
Like we did for Linux and macOS, we add licenses metadata to the PYTHON.json for Windows builds. This required a bit more effort because some libraries are built into the extension itself and there's no easy way to automatically associate libraries with extensions since it is all baked into Visual Studio Project files.
1 parent c27f7fa commit f283e6b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

cpython-windows/build.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@
7979
'faulthandler',
8080
}
8181

82+
# Used to annotate licenses.
83+
EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY = {
84+
'_bz2': 'bzip2',
85+
'_ctypes': 'libffi',
86+
'_hashlib': 'openssl',
87+
'_lzma': 'xz',
88+
'_sqlite3': 'sqlite',
89+
'_ssl': 'openssl',
90+
'_uuid': 'uuid',
91+
'zlib': 'zlib',
92+
}
93+
8294

8395
def log(msg):
8496
if isinstance(msg, bytes):
@@ -1204,6 +1216,16 @@ def find_additional_dependencies(project: pathlib.Path):
12041216
'path_static': 'build/lib/%s.lib' % lib
12051217
})
12061218

1219+
if ext in EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY:
1220+
download_entry = DOWNLOADS[EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY[ext]]
1221+
1222+
# This will raise if no license metadata defined. This is
1223+
# intentional because EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY is
1224+
# manually curated and we want to fail fast.
1225+
entry['licenses'] = download_entry['licenses']
1226+
entry['license_paths'] = ['licenses/%s' % download_entry['license_file']]
1227+
entry['license_public_domain'] = download_entry.get('license_public_domain')
1228+
12071229
res['extensions'][ext] = [entry]
12081230

12091231
# Copy the extension static library.
@@ -1363,9 +1385,15 @@ def build_cpython(pgo=False):
13631385
log('copying %s to %s' % (source, dest))
13641386
shutil.copyfile(source, dest)
13651387

1388+
licenses_dir = out_dir / 'python' / 'licenses'
1389+
licenses_dir.mkdir()
1390+
for f in sorted(os.listdir(ROOT)):
1391+
if f.startswith('LICENSE.') and f.endswith('.txt'):
1392+
shutil.copyfile(ROOT / f, licenses_dir / f)
1393+
13661394
# Create PYTHON.json file describing this distribution.
13671395
python_info = {
1368-
'version': '1',
1396+
'version': '2',
13691397
'os': 'windows',
13701398
'arch': 'x86_64',
13711399
'python_flavor': 'cpython',
@@ -1374,14 +1402,13 @@ def build_cpython(pgo=False):
13741402
'python_include': 'install/include',
13751403
'python_stdlib': 'install/Lib',
13761404
'build_info': build_info,
1405+
'licenses': DOWNLOADS['cpython-3.7']['licenses'],
1406+
'license_path': 'licenses/LICENSE.cpython.txt',
13771407
}
13781408

13791409
with (out_dir / 'python' / 'PYTHON.json').open('w', encoding='utf8') as fh:
13801410
json.dump(python_info, fh, sort_keys=True, indent=4)
13811411

1382-
# Copy software licenses file.
1383-
shutil.copyfile(ROOT / 'python-licenses.rst', out_dir / 'python' / 'LICENSE.rst')
1384-
13851412
dest_path = BUILD / 'cpython-windows.tar'
13861413

13871414
with dest_path.open('wb') as fh:

0 commit comments

Comments
 (0)