From 00727c8eea44cf26ede45fb5276d0311ed8933fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Faria?= Date: Tue, 28 Jan 2025 18:43:00 +0100 Subject: [PATCH] testing wheels --- .github/workflows/publish.yml | 8 +++++ metadata_tilde.py | 67 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 metadata_tilde.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 87c1082..a23a4a2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -26,6 +26,10 @@ jobs: # Needed for full C++17 support CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET='10.15' + - name: Tilde + run: | + python metadata_tilde.py wheel + - uses: actions/upload-artifact@v4 with: name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} @@ -40,6 +44,10 @@ jobs: - name: Build sdist run: pipx run build --sdist + - name: Tilde + run: | + python metadata_tilde.py dist + - uses: actions/upload-artifact@v4 with: name: cibw-sdist diff --git a/metadata_tilde.py b/metadata_tilde.py new file mode 100644 index 0000000..b55c136 --- /dev/null +++ b/metadata_tilde.py @@ -0,0 +1,67 @@ +# what a beautiful hack! +import sys +from glob import glob +from pathlib import Path +import tempfile +import tarfile +import zipfile + +def replace_tilde_in_targz(tar_gz): + with tempfile.TemporaryDirectory() as td: + tdp = Path(td) + + # extract archive to temporry directory + with tarfile.open(tar_gz) as r: + r.extractall(td) + + pkg_info = next(tdp.glob('*/PKG-INFO')) + + # modify PKG-INFO + with pkg_info.open() as f: + text = f.read() + text = text.replace( + 'Author-Email: =?utf-8?q?Jo=C3=A3o_Faria?= ', + 'Author-Email: "João Faria" ' + ) + + with pkg_info.open('wb') as f: + f.write(text.encode()) + + # replace archive, from all files in tempdir + with tarfile.open(tar_gz, "w:gz") as w: + for f in tdp.iterdir(): + w.add(f, arcname=f.name) + +def replace_tilde_in_whl(whl): + with tempfile.TemporaryDirectory() as td: + tdp = Path(td) + + # extract archive to temporry directory + with zipfile.ZipFile(whl) as r: + r.extractall(td) + + metadata = next(tdp.glob('*.dist-info/METADATA')) + + # modify METADATA + with metadata.open() as f: + text = f.read() + text = text.replace( + 'Author-Email: =?utf-8?q?Jo=C3=A3o_Faria?= ', + 'Author-Email: "João Faria" ' + ) + + with metadata.open('wb') as f: + f.write(text.encode()) + + # replace archive, from all files in tempdir + with zipfile.ZipFile(whl, "w") as w: + for f in tdp.rglob('*'): + w.write(f, arcname=f.relative_to(tdp)) + +if 'dist' in sys.argv: + tar_gz = glob('dist/*.tar.gz')[0] + replace_tilde_in_targz(tar_gz) + +if 'wheel' in sys.argv: + for whl in glob('wheelhouse/*.whl'): + replace_tilde_in_whl(whl)