@@ -13,31 +13,23 @@ def main(*args: str):
1313 Update license information in wheels after running auditwheel etc.
1414
1515 Usage:
16- cibw_repair_wheel_licenses.py <dest_dir> < wheel_file> \
16+ cibw_repair_wheel_licenses.py <wheel_file> \
1717 --license MIT --license-file licenses/license_foo_MIT.txt \
1818 --license BSD-3-Clause --license-file licenses/license_bar_BSD-3-Clause.txt \
1919 ...
2020
2121 CWD should be at project root (containing pyproject.toml) and license-file
2222 paths must be relative.
2323
24- The wheel_file argument's basename is the filename but the wheel file
25- is expected to be found in the dest_dir e.g.:
26-
27- $ cibw_repair_wheel_licenses.py dist wheels/foo-1.0.whl
28-
29- means that the wheel is expected to be found at dist/foo-1.0.whl.
30-
31- This command overwrites the wheel file in place.
24+ The wheel_file argument should be the path to the wheel file to be repaired.
25+ It will be overwritten in place.
3226 """
3327 parser = argparse .ArgumentParser ()
34- parser .add_argument ("dest_dir" )
3528 parser .add_argument ("wheel_file" )
3629 parser .add_argument ("--license" , action = "append" , default = [])
3730 parser .add_argument ("--license-file" , action = "append" , default = [])
3831
3932 parsed = parser .parse_args (args )
40- dest_dir = Path (parsed .dest_dir )
4133 wheel_file = Path (parsed .wheel_file )
4234 licenses = parsed .license
4335 license_files = [Path (f ) for f in parsed .license_file ]
@@ -52,27 +44,26 @@ def main(*args: str):
5244 #
5345 raise ValueError ("license-file paths must be relative to project root" )
5446
55- update_licenses_wheel (dest_dir , wheel_file , licenses , license_files )
47+ update_licenses_wheel (wheel_file , licenses , license_files )
5648
5749
5850def update_licenses_wheel (
59- dest_dir : Path , wheel_file : Path , licenses : list [str ], license_files : list [Path ]
51+ wheel_file : Path , licenses : list [str ], license_files : list [Path ]
6052):
6153 # foo/bar-1.0-cp310-cp310-linux_x86_64.whl -> bar-1.0
6254 name , version = wheel_file .stem .split ('-' )[:2 ]
63- wheel_path = dest_dir / wheel_file .name
64- if wheel_path .exists ():
65- print ("Found wheel at" , wheel_path )
55+ if wheel_file .exists ():
56+ print ("Found wheel at" , wheel_file )
6657 else :
67- raise ValueError (f"Wheel not found at { wheel_path } " )
58+ raise ValueError (f"Wheel not found at { wheel_file } " )
6859
6960 base = f"{ name } -{ version } "
7061
7162 with TemporaryDirectory () as tmpdir :
7263
7364 tmpdir = Path (tmpdir )
7465 print ("temp dir:" , tmpdir )
75- run (["wheel" , "unpack" , "--dest" , tmpdir , wheel_path ], check = True )
66+ run (["wheel" , "unpack" , "--dest" , tmpdir , wheel_file ], check = True )
7667 dist_info = tmpdir / base / f"{ base } .dist-info"
7768
7869 print (f"Adding licenses in { dist_info } " )
@@ -88,14 +79,16 @@ def update_licenses_wheel(
8879 new_wheel_file = wheels [0 ]
8980
9081 print (f"Repaired wheel: { new_wheel_file } " )
91- print (f"Copying to { wheel_path } " )
92- copyfile (new_wheel_file , wheel_path )
82+ print (f"Copying back to: { wheel_file } " )
83+ copyfile (new_wheel_file , wheel_file )
9384
9485
9586def update_license_dist_info (
9687 dist_info : Path , licenses : list [str ], license_files : list [Path ]
9788):
9889 for license_file in license_files :
90+ if license_file .exists ():
91+ raise ValueError (f"license file already present: { license_file } " )
9992 makedirs (dist_info / license_file .parent , exist_ok = True )
10093 copyfile (license_file , dist_info / license_file )
10194 print (f"Added license file { license_file } " )
0 commit comments