in xar/pip_installer.py [0:0]
def extract_sdist(self, sdist, dest):
"""
Extract the sdist archive and return the path to the source.
"""
if sdist.lower().endswith(".zip"):
open_sdist = zipfile.ZipFile
error_cls = zipfile.BadZipfile
else:
assert ".tar" in sdist.lower()
open_sdist = tarfile.TarFile.open
error_cls = tarfile.ReadError
try:
with contextlib.closing(open_sdist(sdist)) as archive:
archive.extractall(path=dest)
def collapse_trivial(path):
entries = os.listdir(path)
if len(entries) == 1:
entry = os.path.join(path, entries[0])
if os.path.isdir(entry):
return collapse_trivial(entry)
return path
return collapse_trivial(dest)
except error_cls:
raise BuildException("Failed to extract %s" % os.path.basename(sdist))