Skip to content

Commit

Permalink
add script to add license full text file to wheel dist-info
Browse files Browse the repository at this point in the history
maturing has issues embedding license full text in the wheels so for now we do it ourselves.
PyO3/maturin#829

There's another problem using wheeltools on windows (it creates zip files with backslashes...) so I run this on Linux after all the wheels have been built.
  • Loading branch information
anthrotype committed Mar 8, 2022
1 parent 2a89cde commit 8274bbc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,24 @@ jobs:
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"

- uses: actions/download-artifact@v2
with:
name: dist
path: dist

# https://github.com/PyO3/maturin/issues/829
- name: Add license text file to wheels
run: |
pip install wheeltools
python add_license_file_to_wheels.py dist/*.whl
- name: Extract release notes from annotated tag message
id: release_notes
env:
Expand Down
25 changes: 25 additions & 0 deletions add_license_file_to_wheels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

import sys
from pathlib import Path
import shutil
from wheeltools import InWheel


root_dir = Path(__file__).parent.resolve()
crate_dir = root_dir / "pngquant"
license = crate_dir / "COPYRIGHT"


def main():
# maturin has problems adding the license text to the wheel archive yet so we
# have to do it ourselves: cf. https://github.com/PyO3/maturin/issues/829
for wheel_file in sys.argv[1:]:
with InWheel(in_wheel=wheel_file, out_wheel=wheel_file) as tmpdir:
distinfo = next(Path(tmpdir).glob("*.dist-info"))
assert distinfo.is_dir()
shutil.copyfile(license, distinfo / "LICENSE")


if __name__ == "__main__":
sys.exit(main())
13 changes: 2 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
import sys
from pathlib import Path
from wheeltools import InWheel


root_dir = Path(__file__).parent.resolve()
Expand Down Expand Up @@ -38,18 +37,10 @@ def main():
except (IndexError, KeyError):
sys.exit("usage: build.py [sdist|wheel]")

subprocess.run(
cmd + ["-o", str(dist_dir)] + sys.argv[2:], check=True, cwd=str(crate_dir)
return subprocess.call(
cmd + ["-o", str(dist_dir)] + sys.argv[2:], cwd=str(crate_dir)
)

# maturin doesn't add the license text to the wheel archive yet so we
# have to do it ourselves: cf. https://github.com/PyO3/maturin/issues/829
for wheel_file in dist_dir.glob("pngquant*.whl"):
with InWheel(in_wheel=str(wheel_file), out_wheel=str(wheel_file)) as tmpdir:
distinfo = next(Path(tmpdir).glob("*.dist-info"))
assert distinfo.is_dir()
shutil.copyfile(crate_dir / "COPYRIGHT", distinfo / "LICENSE")


if __name__ == "__main__":
sys.exit(main())
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ maturin
tomli
tomli-w
twine
wheeltools

0 comments on commit 8274bbc

Please sign in to comment.