Skip to content

Commit 27a91ac

Browse files
Update tarball extraction
1 parent 322ea9b commit 27a91ac

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

PCbuild/get_external.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import argparse
44
import os
55
import pathlib
6-
import shutil
76
import sys
7+
import tarfile
88
import time
99
import urllib.error
1010
import urllib.request
@@ -55,9 +55,15 @@ def fetch_release(tag, tarball_dir, *, org='python', verbose=False):
5555

5656

5757
def extract_tarball(externals_dir, tarball_path, tag):
58-
output_path = externals_dir / tag
59-
shutil.unpack_archive(os.fspath(tarball_path), os.fspath(output_path))
60-
return output_path
58+
# Extract to externals_dir and return the path to the first top-level directory
59+
with tarfile.open(tarball_path) as tf:
60+
# Get the first top-level directory name from the tarball
61+
members = tf.getmembers()
62+
if not members:
63+
raise ValueError(f"Tarball {tarball_path} is empty")
64+
top_level_dir = members[0].name.split('/')[0]
65+
tf.extractall(os.fspath(externals_dir))
66+
return externals_dir / top_level_dir
6167

6268

6369
def extract_zip(externals_dir, zip_path):

0 commit comments

Comments
 (0)