in src/sagemaker_training/files.py [0:0]
def download_and_extract(uri, path): # type: (str, str) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as
an entry point.
SageMaker Python SDK saves the user provided entry points as compressed tar files in S3
Args:
uri (str): the location of the entry point.
path (bool): The path where the script will be installed. It will not download and
install the if the path already has the user entry point.
"""
if not os.path.exists(path):
os.makedirs(path)
if not os.listdir(path):
with tmpdir() as tmp:
if uri.startswith("s3://"):
dst = os.path.join(tmp, "tar_file")
s3_download(uri, dst)
with tarfile.open(name=dst, mode="r:gz") as t:
t.extractall(path=path)
elif os.path.isdir(uri):
if uri == path:
return
if os.path.exists(path):
shutil.rmtree(path)
shutil.copytree(uri, path)
elif tarfile.is_tarfile(uri):
with tarfile.open(name=uri, mode="r:gz") as t:
t.extractall(path=path)
else:
shutil.copy2(uri, path)