Skip to content

Commit 2098a54

Browse files
committed
Put licenses in the licenses directory
1 parent 8d5feb3 commit 2098a54

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

bin/cibw_repair_wheel_licenses.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ def main(*args: str):
3535
license_files = [Path(f) for f in parsed.license_file]
3636

3737
if any(f.is_absolute() for f in license_files):
38-
#
39-
# PEP 639 says:
40-
#
41-
# Inside the root license directory, packaging tools MUST reproduce the
42-
# directory structure under which the source license files are located
43-
# relative to the project root.
44-
#
4538
raise ValueError("license-file paths must be relative to project root")
4639

4740
update_licenses_wheel(wheel_file, licenses, license_files)
@@ -87,10 +80,18 @@ def update_license_dist_info(
8780
dist_info: Path, licenses: list[str], license_files: list[Path]
8881
):
8982
for license_file in license_files:
90-
if license_file.exists():
83+
wheel_license_path = dist_info / "licenses" / license_file.name
84+
if wheel_license_path.exists():
9185
raise ValueError(f"license file already present: {license_file}")
86+
#
87+
# PEP 639 says:
88+
#
89+
# Inside the root license directory, packaging tools MUST reproduce the
90+
# directory structure under which the source license files are located
91+
# relative to the project root.
92+
#
9293
makedirs(dist_info / license_file.parent, exist_ok=True)
93-
copyfile(license_file, dist_info / license_file)
94+
copyfile(license_file, wheel_license_path)
9495
print(f"Added license file {license_file}")
9596

9697
metadata_file = dist_info / "METADATA"
@@ -118,9 +119,12 @@ def update_license_dist_info(
118119
if not license_files_lines:
119120
raise ValueError("Could not find License-File in METADATA")
120121

121-
last_index = lines.index(license_files_lines[-1])
122+
index = lines.index(license_files_lines[-1]) + 1
122123
new_lines = [f"License-File: {f}\n" for f in license_files]
123-
lines = lines[:last_index] + new_lines + lines[last_index:]
124+
lines = lines[:index] + new_lines + lines[index:]
125+
126+
print("Writing out METADATA with updated License-Expression and License-File fields")
127+
print("Writing to:", metadata_file)
124128

125129
with open(metadata_file, "w") as f:
126130
f.writelines(lines)

0 commit comments

Comments
 (0)