Skip to content

Commit af35bbe

Browse files
author
Jonathan Esterhazy
committed
update docstring
1 parent 9c5c4f3 commit af35bbe

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/sagemaker/fw_utils.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15+
from collections import namedtuple
16+
1517
import os
1618
import re
19+
import sagemaker.utils
1720
import shutil
1821
import tempfile
19-
from collections import namedtuple
2022
from six.moves.urllib.parse import urlparse
2123

22-
import sagemaker.utils
23-
2424
_TAR_SOURCE_FILENAME = 'source.tar.gz'
2525

2626
UploadedCode = namedtuple('UserCode', ['s3_prefix', 'script_name'])
@@ -112,24 +112,32 @@ def validate_source_dir(script, directory):
112112

113113

114114
def tar_and_upload_dir(session, bucket, s3_key_prefix, script, directory, dependencies=None):
115-
"""Pack and upload source files to S3 only if directory is empty or local.
115+
"""Package source files and upload a compress tar file to S3. The S3 location will be
116+
``s3://<bucket>/s3_key_prefix/sourcedir.tar.gz``.
117+
118+
If directory is an S3 URI, an UploadedCode object will be returned, but nothing will be
119+
uploaded to S3 (this allow reuse of code already in S3).
120+
121+
If directory is None, the script will be added to the archive at ``./<basename of script>``.
116122
117-
Note:
118-
If the directory points to S3 no action is taken.
123+
If directory is not None, the (recursive) contents of the directory will be added to
124+
the archive. directory is treated as the base path of the archive, and the script name is
125+
assumed to be a filename or relative path inside the directory.
119126
120127
Args:
121128
session (boto3.Session): Boto session used to access S3.
122129
bucket (str): S3 bucket to which the compressed file is uploaded.
123130
s3_key_prefix (str): Prefix for the S3 key.
124-
script (str): Script filename.
125-
directory (str or None): Directory containing the source file. If it starts with
126-
"s3://", no action is taken.
127-
dependencies (List[str]): A list of paths to directories (absolute or relative)
131+
script (str): Script filename or path.
132+
directory (str): Optional. Directory containing the source file. If it starts with "s3://",
133+
no action is taken.
134+
dependencies (List[str]): Optional. A list of paths to directories (absolute or relative)
128135
containing additional libraries that will be copied into
129136
/opt/ml/lib
130137
131138
Returns:
132-
sagemaker.fw_utils.UserCode: An object with the S3 bucket and key (S3 prefix) and script name.
139+
sagemaker.fw_utils.UserCode: An object with the S3 bucket and key (S3 prefix) and
140+
script name.
133141
"""
134142
if directory and directory.lower().startswith('s3://'):
135143
return UploadedCode(s3_prefix=directory, script_name=os.path.basename(script))
@@ -141,7 +149,8 @@ def tar_and_upload_dir(session, bucket, s3_key_prefix, script, directory, depend
141149

142150
try:
143151
source_files = _list_files_to_compress(script, directory) + dependencies
144-
tar_file = sagemaker.utils.create_tar_file(source_files, os.path.join(tmp, _TAR_SOURCE_FILENAME))
152+
tar_file = sagemaker.utils.create_tar_file(source_files,
153+
os.path.join(tmp, _TAR_SOURCE_FILENAME))
145154

146155
session.resource('s3').Object(bucket, key).upload_file(tar_file)
147156
finally:

0 commit comments

Comments
 (0)