14
14
from __future__ import absolute_import
15
15
16
16
import os
17
- import pathlib
18
17
import shutil
19
18
20
19
from distutils .dir_util import copy_tree
21
20
from six .moves .urllib .parse import urlparse
22
21
22
+ from sagemaker import s3
23
+
23
24
24
25
def copy_directory_structure (destination_directory , relative_path ):
25
26
"""Create all the intermediate directories required for relative_path to
@@ -63,8 +64,8 @@ def move_to_destination(source, destination, job_name, sagemaker_session):
63
64
final_uri = destination
64
65
elif parsed_uri .scheme == "s3" :
65
66
bucket = parsed_uri .netloc
66
- path = _create_s3_prefix (parsed_uri .path , job_name )
67
- final_uri = "s3://%s/%s" % (bucket , path )
67
+ path = s3 . s3_path_join (parsed_uri .path , job_name )
68
+ final_uri = s3 . s3_path_join (bucket , path )
68
69
sagemaker_session .upload_data (source , bucket , path )
69
70
else :
70
71
raise ValueError ("Invalid destination URI, must be s3:// or file://, got: %s" % destination )
@@ -73,21 +74,6 @@ def move_to_destination(source, destination, job_name, sagemaker_session):
73
74
return final_uri
74
75
75
76
76
- def _create_s3_prefix (path , job_name ):
77
- """Constructs a path out of the given path and job name to be
78
- used as an S3 prefix.
79
-
80
- Args:
81
- path (str): the original path. If the path is only ``"/"``,
82
- then it is ignored.
83
- job_name (str): the job name to be appended to the path.
84
-
85
- Returns:
86
- str: an S3 prefix of the form ``"path/job_name"``
87
- """
88
- return job_name if path == "" else str (pathlib .PurePosixPath (path , job_name ))
89
-
90
-
91
77
def recursive_copy (source , destination ):
92
78
"""A wrapper around distutils.dir_util.copy_tree but won't throw any
93
79
exception when the source directory does not exist.
0 commit comments