Skip to content

Commit 446c875

Browse files
committed
Drop compiled artifacts
1 parent 8f93d34 commit 446c875

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ c_lib:
3838
.PHONY: package
3939
package: c_lib
4040
python -m build --no-isolation
41+
python ./update_sdist.py
4142
twine check dist/*

update_sdist.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
update_sdist.py
3+
4+
Run this script to remove compiled artifacts from source distribution tarballs.
5+
"""
6+
from pathlib import Path
7+
from tarfile import open as tar_open
8+
from tempfile import TemporaryDirectory
9+
10+
REMOVE_FILES = frozenset(['ada_url/ada.o'])
11+
12+
13+
def update_archive(file_path, removals):
14+
with TemporaryDirectory() as temp_dir:
15+
with tar_open(file_path, mode='r:gz') as tf:
16+
tf.extractall(temp_dir)
17+
18+
dir_path = next(Path(temp_dir).glob('ada_url-*'))
19+
all_files = []
20+
for file_path in Path(temp_dir).glob('**/*'):
21+
if file_path.is_dir():
22+
continue
23+
if str(file_path.relative_to(dir_path)) in REMOVE_FILES:
24+
continue
25+
all_files.append(file_path)
26+
27+
with tar_open(file_path, mode='w:gz') as tf:
28+
for file_path in all_files:
29+
arcname = file_path.relative_to(temp_dir)
30+
print(arcname)
31+
tf.add(file_path, arcname=arcname)
32+
33+
34+
if __name__ == '__main__':
35+
for file_path in Path().glob('dist/*.tar.gz'):
36+
update_archive(file_path, REMOVE_FILES)
37+
print(f'Updated {file_path}')

0 commit comments

Comments
 (0)