Skip to content

Commit 9167836

Browse files
committed
linux: add license into to PYTHON.json
Now that we've annotated licenses for libraries, it is time to add that annotation to the PYTHON.json file. We bump the version of PYTHON.json to 2 and define fields to hold license info. We annotate libraries with their library names so we can find licenses from link requirements. Then we hook it all together and add the license annotations to PYTHON.json and add the license files to the distribution.
1 parent 61f2e12 commit 9167836

File tree

5 files changed

+87
-9
lines changed

5 files changed

+87
-9
lines changed

README.rst

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ PYTHON.json
239239

240240
See the ``PYTHON.json File`` section for the format of this file.
241241

242-
LICENSE.rst
243-
Contains license information of software contained in the distribution.
244-
245242
By convention, the ``build/`` directory contains artifacts from building
246243
this distribution (object files, libraries, etc) and the ``install/`` directory
247244
contains a working, self-contained Python installation of this distribution.
@@ -259,7 +256,7 @@ without having to resort to heuristics.
259256
The file contains a JSON map. This map has the following keys:
260257

261258
version
262-
Version number of the file format. Currently ``1``.
259+
Version number of the file format. Currently ``2``.
263260

264261
os
265262
Target operating system for the distribution. e.g. ``linux``, ``macos``,
@@ -291,6 +288,17 @@ build_info
291288

292289
See the ``build_info Data`` section below.
293290

291+
licenses
292+
Array of strings containing the license shortname identifiers from the
293+
SPDX license list (https://spdx.org/licenses/) for the Python distribution.
294+
295+
(Version 2 or above only.)
296+
297+
license_path
298+
Path to a text file containing the license for this Python distribution.
299+
300+
(Version 2 or above only.)
301+
294302
build_info Data
295303
---------------
296304

@@ -391,3 +399,25 @@ system
391399

392400
System libraries are typically passed into the linker by name only and
393401
found using default library search paths.
402+
403+
licenses
404+
Array of strings containing the license shortname identifiers from the
405+
SPDX license list (https://spdx.org/licenses/).
406+
407+
If this field is missing, licenses are unknown. Empty array denotes no known
408+
licenses.
409+
410+
(Version 2 or above only.)
411+
412+
license_path
413+
Path to a text file containing the license for this library.
414+
415+
(Version 2 or above only.)
416+
417+
license_public_domain
418+
Bool indicating that the library is in the public domain.
419+
420+
There is no SPDX identifier for public domain. And we want to be explicit
421+
about something being in the public domain because of the legal implications.
422+
423+
(Version 2 or above only.)

cpython-linux/build-cpython.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,6 @@ cp -av Modules/config.c.in /build/out/python/build/Modules/
171171
cp -av Python/frozen.c /build/out/python/build/Python/
172172
cp -av Modules/Setup.dist /build/out/python/build/Modules/
173173
cp -av Modules/Setup.local /build/out/python/build/Modules/
174-
cp /build/python-licenses.rst /build/out/python/LICENSE.rst
174+
175+
mkdir /build/out/python/licenses
176+
cp /build/LICENSE.*.txt /build/out/python/licenses/

cpython-linux/build.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
DOWNLOADS,
2626
)
2727
from pythonbuild.utils import (
28+
add_license_to_link_entry,
2829
download_entry,
2930
)
3031

@@ -538,10 +539,14 @@ def process_setup_line(line, variant=None):
538539
log('adding library %s for extension %s' % (libname, extension))
539540

540541
if libname in libraries:
541-
links.append({
542+
entry = {
542543
'name': libname,
543544
'path_static': 'build/lib/lib%s.a' % libname,
544-
})
545+
}
546+
547+
add_license_to_link_entry(entry)
548+
549+
links.append(entry)
545550
else:
546551
links.append({
547552
'name': libname,
@@ -667,7 +672,10 @@ def build_cpython(client, image, platform, optimized=False, musl=False):
667672
copy_file_to_container(pip_archive, container, '/build')
668673
copy_file_to_container(SUPPORT / 'build-cpython.sh', container,
669674
'/build')
670-
copy_file_to_container(ROOT / 'python-licenses.rst', container, '/build')
675+
676+
for f in sorted(os.listdir(ROOT)):
677+
if f.startswith('LICENSE.') and f.endswith('.txt'):
678+
copy_file_to_container(ROOT / f, container, '/build')
671679

672680
# TODO copy latest pip/setuptools.
673681

@@ -705,7 +713,7 @@ def build_cpython(client, image, platform, optimized=False, musl=False):
705713

706714
# Create PYTHON.json file describing this distribution.
707715
python_info = {
708-
'version': '1',
716+
'version': '2',
709717
'os': 'linux',
710718
'arch': 'x86_64',
711719
'python_flavor': 'cpython',
@@ -715,6 +723,8 @@ def build_cpython(client, image, platform, optimized=False, musl=False):
715723
'python_stdlib': 'install/lib/python3.7',
716724
'build_info': python_build_info(container, config_c_in,
717725
setup_dist_content, setup_local_content),
726+
'licenses': DOWNLOADS['cpython-3.7']['licenses'],
727+
'license_path': 'licenses/LICENSE.cpython.txt',
718728
}
719729

720730
with tempfile.NamedTemporaryFile('w') as fh:

pythonbuild/downloads.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'size': 36541923,
1010
'sha256': '2917c28f60903908c2ca4587ded1363b812c4e830a5326aaa77c9879d13ae18e',
1111
'version': '6.0.19',
12+
'library_names': ['db'],
1213
'licenses': ['Sleepycat'],
1314
'license_file': 'LICENSE.bdb.txt',
1415
},
@@ -23,6 +24,7 @@
2324
'size': 782025,
2425
'sha256': 'a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd',
2526
'version': '1.0.6',
27+
'library_names': ['bz2'],
2628
'licenses': ['bzip2-1.0.6'],
2729
'license_file': 'LICENSE.bzip2.txt',
2830
},
@@ -81,6 +83,7 @@
8183
'size': 941863,
8284
'sha256': '86e613527e5dba544e73208f42b78b7c022d4fa5a6d5498bf18c8d6f745b91dc',
8385
'version': '1.18.1',
86+
'library_names': ['gdbm'],
8487
'licenses': ['GPL-3.0-or-later'],
8588
'license_file': 'LICENSE.gdbm.txt',
8689
},
@@ -125,6 +128,7 @@
125128
'size': 521931,
126129
'sha256': '2811d70c0b000f2ca91b7cb1a37203134441743c4fcc9c37b0b687f328611064',
127130
'version': '20181209-3.1',
131+
'library_names': ['edit'],
128132
'licenses': ['BSD-3-Clause'],
129133
'license_file': 'LICENSE.libedit.txt',
130134
},
@@ -133,6 +137,7 @@
133137
'size': 940837,
134138
'sha256': 'd06ebb8e1d9a22d19e38d63fdb83954253f39bedc5d46232a05645685722ca37',
135139
'version': '3.2.1',
140+
'library_names': ['ffi'],
136141
'licenses': ['MIT'],
137142
'license_file': 'LICENSE.libffi.txt',
138143
},
@@ -188,6 +193,7 @@
188193
'size': 3365395,
189194
'sha256': 'aa057eeeb4a14d470101eff4597d5833dcef5965331be3528c08d99cebaa0d17',
190195
'version': '6.1',
196+
'library_names': ['ncurses', 'panel'],
191197
'licenses': ['X11'],
192198
'license_file': 'LICENSE.ncurses.txt',
193199
},
@@ -208,6 +214,7 @@
208214
'size': 8213737,
209215
'sha256': '5c557b023230413dfb0756f3137a13e6d726838ccd1430888ad15bfb2b43ea4b',
210216
'version': '1.1.1b',
217+
'library_names': ['crypto', 'ssl'],
211218
'licenses': ['OpenSSL'],
212219
'license_file': 'LICENSE.openssl.txt',
213220
},
@@ -228,6 +235,7 @@
228235
'size': 2468560,
229236
'sha256': '56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43',
230237
'version': '6.3',
238+
'library_names': ['readline'],
231239
'licenses': ['GPL-3.0'],
232240
'license_file': 'LICENSE.readline.txt',
233241
},
@@ -248,7 +256,10 @@
248256
'sha256': 'd61b5286f062adfce5125eaf544d495300656908e61fca143517afcc0a89b7c3',
249257
'version': '3280000',
250258
'actual_version': '3.28.0.0',
259+
'library_names': ['sqlite3'],
260+
'licenses': [],
251261
'license_file': 'LICENSE.sqlite.txt',
262+
'license_public_domain': True,
252263
},
253264
'strawberryperl': {
254265
'url': 'http://strawberryperl.com/download/5.28.1.1/strawberry-perl-5.28.1.1-32bit-portable.zip',
@@ -278,6 +289,7 @@
278289
'size': 318256,
279290
'sha256': '46af3275291091009ad7f1b899de3d0cea0252737550e7919d17237997db5644',
280291
'version': '1.0.3',
292+
'library_names': ['uuid'],
281293
'licenses': ['BSD-3-Clause'],
282294
'license_file': 'LICENSE.libuuid.txt',
283295
},
@@ -286,15 +298,19 @@
286298
'size': 1572354,
287299
'sha256': 'b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145',
288300
'version': '5.2.4',
301+
'library_names': ['lzma'],
289302
# liblzma is in the public domain. Other parts of code have licenses. But
290303
# we only use liblzma.
304+
'licenses': [],
291305
'license_file': 'LICENSE.liblzma.txt',
306+
'license_public_domain': True,
292307
},
293308
'zlib': {
294309
'url': 'https://zlib.net/zlib-1.2.11.tar.gz',
295310
'size': 607698,
296311
'sha256': 'c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1',
297312
'version': '1.2.11',
313+
'library_names': ['z'],
298314
'licenses': ['Zlib'],
299315
'license_file': 'LICENSE.zlib.txt',
300316
},

pythonbuild/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,23 @@ def compress_python_archive(source_path: pathlib.Path,
157157
print('%s has SHA256 %s' % (dest_path, hash_path(dest_path)))
158158

159159
return dest_path
160+
161+
162+
def add_license_to_link_entry(entry):
163+
"""Add licenses keys to a ``link`` entry for JSON distribution info."""
164+
name = entry['name']
165+
166+
for value in DOWNLOADS.values():
167+
if name not in value.get('library_names', []):
168+
continue
169+
170+
# Don't add licenses annotations if they aren't defined. This leaves
171+
# things as "unknown" to consumers.
172+
if 'licenses' not in value:
173+
continue
174+
175+
entry['licenses'] = value['licenses']
176+
entry['license_path'] = 'licenses/%s' % value['license_file']
177+
entry['license_public_domain'] = value.get('license_public_domain', False)
178+
179+
return

0 commit comments

Comments
 (0)