Skip to content

Commit

Permalink
testing wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
j-faria committed Jan 28, 2025
1 parent 3563170 commit 00727c8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
67 changes: 67 additions & 0 deletions metadata_tilde.py
Original file line number Diff line number Diff line change
@@ -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?= <[email protected]>',
'Author-Email: "João Faria" <[email protected]>'
)

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?= <[email protected]>',
'Author-Email: "João Faria" <[email protected]>'
)

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)

0 comments on commit 00727c8

Please sign in to comment.