Skip to content

Commit

Permalink
Drop compiled artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles committed Jun 21, 2024
1 parent 8f93d34 commit 446c875
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ c_lib:
.PHONY: package
package: c_lib
python -m build --no-isolation
python ./update_sdist.py
twine check dist/*
37 changes: 37 additions & 0 deletions update_sdist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
update_sdist.py
Run this script to remove compiled artifacts from source distribution tarballs.
"""
from pathlib import Path
from tarfile import open as tar_open
from tempfile import TemporaryDirectory

REMOVE_FILES = frozenset(['ada_url/ada.o'])


def update_archive(file_path, removals):
with TemporaryDirectory() as temp_dir:
with tar_open(file_path, mode='r:gz') as tf:
tf.extractall(temp_dir)

dir_path = next(Path(temp_dir).glob('ada_url-*'))
all_files = []
for file_path in Path(temp_dir).glob('**/*'):
if file_path.is_dir():
continue
if str(file_path.relative_to(dir_path)) in REMOVE_FILES:
continue
all_files.append(file_path)

with tar_open(file_path, mode='w:gz') as tf:
for file_path in all_files:
arcname = file_path.relative_to(temp_dir)
print(arcname)
tf.add(file_path, arcname=arcname)


if __name__ == '__main__':
for file_path in Path().glob('dist/*.tar.gz'):
update_archive(file_path, REMOVE_FILES)
print(f'Updated {file_path}')

0 comments on commit 446c875

Please sign in to comment.