Skip to content

Commit 135069b

Browse files
committed
global: move license annotation to extensions entry
Having it in links implied the existence of a separate library file that was linked against. This isn't always true, including on Windows where the object files for the library can be compiled into the main Python binary directly.
1 parent cbb395a commit 135069b

File tree

4 files changed

+66
-45
lines changed

4 files changed

+66
-45
lines changed

README.rst

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,33 @@ extensions
359359
The string value may be ``NULL``, which may need special handling by
360360
consumers.
361361

362+
licenses
363+
Array of strings containing the license shortname identifiers from the
364+
SPDX license list (https://spdx.org/licenses/).
365+
366+
If this field is missing, licenses are unknown. Empty array denotes no known
367+
licenses.
368+
369+
The license applies to additional libraries needed by this extension, not
370+
the extension itself, as extensions should be licensed the same as the
371+
Python distribution.
372+
373+
(Version 2 or above only.)
374+
375+
license_path
376+
Paths to text files containing the licenses for this extension.
377+
378+
(Version 2 or above only.)
379+
380+
license_public_domain
381+
Bool indicating that the license for the extension is in the public
382+
domain.
383+
384+
There is no SPDX identifier for public domain. And we want to be explicit
385+
about something being in the public domain because of the legal implications.
386+
387+
(Version 2 or above only.)
388+
362389
links
363390
An array of linking requirement maps. (See below for data format.)
364391

@@ -399,25 +426,3 @@ system
399426

400427
System libraries are typically passed into the linker by name only and
401428
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.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
DOWNLOADS,
2626
)
2727
from pythonbuild.utils import (
28-
add_license_to_link_entry,
28+
add_licenses_to_extension_entry,
2929
download_entry,
3030
)
3131

@@ -544,23 +544,24 @@ def process_setup_line(line, variant=None):
544544
'path_static': 'build/lib/lib%s.a' % libname,
545545
}
546546

547-
add_license_to_link_entry(entry)
548-
549547
links.append(entry)
550548
else:
551549
links.append({
552550
'name': libname,
553551
'system': True,
554552
})
555553

556-
bi['extensions'].setdefault(extension, []).append({
554+
entry = {
557555
'in_core': False,
558556
'init_fn': 'PyInit_%s' % extension,
559557
'links': links,
560558
'objs': objs,
561559
'variant': d['variant'],
562-
})
560+
}
561+
562+
add_licenses_to_extension_entry(entry)
563563

564+
bi['extensions'].setdefault(extension, []).append(entry)
564565

565566
found_start = False
566567

cpython-macos/build.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
DOWNLOADS,
2323
)
2424
from pythonbuild.utils import (
25-
add_license_to_link_entry,
25+
add_licenses_to_extension_entry,
2626
create_tar_from_directory,
2727
download_entry,
2828
extract_tar_to_directory,
@@ -244,22 +244,24 @@ def process_setup_line(line):
244244
'path_static': 'build/lib/lib%s.a' % libname,
245245
}
246246

247-
add_license_to_link_entry(entry)
248-
249247
links.append(entry)
250248
else:
251249
links.append({
252250
'name': libname,
253251
'system': True,
254252
})
255253

256-
bi['extensions'][extension] = [{
254+
entry = {
257255
'in_core': False,
258256
'init_fn': 'PyInit_%s' % extension,
259257
'links': links,
260258
'objs': objs,
261259
'variant': 'default',
262-
}]
260+
}
261+
262+
add_licenses_to_extension_entry(entry)
263+
264+
bi['extensions'][extension] = [entry]
263265

264266
found_start = False
265267

pythonbuild/utils.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,34 @@ def compress_python_archive(source_path: pathlib.Path,
159159
return dest_path
160160

161161

162-
def add_license_to_link_entry(entry):
163-
"""Add licenses keys to a ``link`` entry for JSON distribution info."""
164-
name = entry['name']
162+
def add_licenses_to_extension_entry(entry):
163+
"""Add licenses keys to a ``extensions`` entry for JSON distribution info."""
165164

166-
for value in DOWNLOADS.values():
167-
if name not in value.get('library_names', []):
168-
continue
165+
have_licenses = False
166+
licenses = set()
167+
license_paths = set()
168+
license_public_domain = None
169169

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
170+
for link in entry['links']:
171+
name = link['name']
174172

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)
173+
for value in DOWNLOADS.values():
174+
if name not in value.get('library_names', []):
175+
continue
178176

177+
# Don't add licenses annotations if they aren't defined. This leaves
178+
# things as "unknown" to consumers.
179+
if 'licenses' not in value:
180+
continue
181+
182+
have_licenses = True
183+
licenses |= set(value['licenses'])
184+
license_paths.add('licenses/%s' % value['license_file'])
185+
license_public_domain = value.get('license_public_domain', False)
186+
187+
if not have_licenses:
179188
return
189+
190+
entry['licenses'] = sorted(licenses)
191+
entry['license_paths'] = sorted(license_paths)
192+
entry['license_public_domain'] = license_public_domain

0 commit comments

Comments
 (0)