From 285cc2b24819e632e25803e9a0afadbe6c6dc647 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sat, 5 Mar 2022 11:00:33 +0000 Subject: [PATCH 1/2] use wheeltools to unpack/repack wheel for copying LICENSE file --- build.py | 13 +++++++++++-- requirements.txt | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build.py b/build.py index 1bf1d30..c953ad1 100755 --- a/build.py +++ b/build.py @@ -6,6 +6,7 @@ import subprocess import sys from pathlib import Path +from wheeltools import InWheel root_dir = Path(__file__).parent.resolve() @@ -37,10 +38,18 @@ def main(): except (IndexError, KeyError): sys.exit("usage: build.py [sdist|wheel]") - return subprocess.call( - cmd + ["-o", str(dist_dir)] + sys.argv[2:], cwd=str(crate_dir) + subprocess.run( + cmd + ["-o", str(dist_dir)] + sys.argv[2:], check=True, 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()) diff --git a/requirements.txt b/requirements.txt index a9ee414..9b77ee3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ maturin tomli tomli-w twine +wheeltools From 20b62ae40bc18b1ff3c22c37477718c66bcb2206 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Sat, 5 Mar 2022 11:01:05 +0000 Subject: [PATCH 2/2] ci: test installing and running pngquant binary --- .github/workflows/ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2ffbda..638fb16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,6 +50,11 @@ jobs: run: pip install -r requirements.txt - name: Build wheel - x86_64 run: python build.py wheel + - name: Install wheel + run: | + pip install --no-index --find-links dist/ --force-reinstall pngquant-cli + which pngquant + pngquant --version - name: Build wheels - universal2 run: python build.py wheel --universal2 - name: Upload wheel @@ -85,6 +90,12 @@ jobs: run: pip install -r requirements.txt - name: Build wheel run: python build.py wheel --target ${{matrix.platform.target}} + - name: Install wheel + shell: bash + run: | + pip install --no-index --find-links dist/ --force-reinstall pngquant-cli + which pngquant + pngquant --version - name: Upload wheel uses: actions/upload-artifact@v2 with: @@ -121,6 +132,12 @@ jobs: run: | export PATH=$PYTHON_DIR:$PATH python build.py wheel + - name: Install wheel + run: | + export PATH=$PYTHON_DIR:$PATH + pip install --no-index --find-links dist/ --force-reinstall pngquant-cli + which pngquant + pngquant --version - name: Upload wheels uses: actions/upload-artifact@v2 with: