Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sagemaker-core/src/sagemaker/core/workflow/utilities.py
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right before the line dependencies = dependencies or [], can you add a comment explaining why you made this decision?

Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str]
str: A hash string representing the unique code artifact(s) for the step
"""

# SourceCode.requirements and other upstream dependency fields default to None
# when not explicitly set. Since this function concatenates dependencies via list
# addition (e.g. [source_dir] + dependencies), we default None to an empty list
# to prevent TypeError.
dependencies = dependencies or []

# FrameworkProcessor
if source_dir:
source_dir_url = urlparse(source_dir)
Expand Down
56 changes: 56 additions & 0 deletions sagemaker-core/tests/unit/workflow/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ def test_get_processing_dependencies_multiple_lists(self):

assert result == ["dep1", "dep2", "dep3", "dep4", "dep5"]

def test_get_processing_code_hash_with_none_dependencies_and_code_only(self):
"""Test get_processing_code_hash with None dependencies and code only"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
f.write("print('hello')")
temp_file = f.name

try:
result = get_processing_code_hash(code=temp_file, source_dir=None, dependencies=None)

assert result is not None
assert len(result) == 64
finally:
os.unlink(temp_file)

def test_get_processing_code_hash_with_none_dependencies_and_source_dir(self):
"""Test get_processing_code_hash with None dependencies and source_dir"""
with tempfile.TemporaryDirectory() as temp_dir:
code_file = Path(temp_dir, "script.py")
code_file.write_text("print('hello')")

result = get_processing_code_hash(
code=str(code_file), source_dir=temp_dir, dependencies=None
)

assert result is not None
assert len(result) == 64

def test_get_processing_code_hash_with_source_dir(self):
"""Test get_processing_code_hash with source_dir"""
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down Expand Up @@ -264,6 +291,35 @@ def test_get_processing_code_hash_with_dependencies(self):

assert result is not None

def test_get_training_code_hash_with_none_dependencies_and_source_dir(self):
"""Test get_training_code_hash with None dependencies and source_dir"""
with tempfile.TemporaryDirectory() as temp_dir:
entry_file = Path(temp_dir, "train.py")
entry_file.write_text("print('training')")

result = get_training_code_hash(
entry_point=str(entry_file), source_dir=temp_dir, dependencies=None
)

assert result is not None
assert len(result) == 64

def test_get_training_code_hash_with_none_dependencies_and_entry_point(self):
"""Test get_training_code_hash with None dependencies and entry_point only"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
f.write("print('training')")
temp_file = f.name

try:
result = get_training_code_hash(
entry_point=temp_file, source_dir=None, dependencies=None
)

assert result is not None
assert len(result) == 64
finally:
os.unlink(temp_file)

def test_get_training_code_hash_with_source_dir(self):
"""Test get_training_code_hash with source_dir"""
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down
Loading