Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 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 @@ -173,6 +173,8 @@ def get_code_hash(step: Entity) -> str:
source_code = model_trainer.source_code
if source_code:
source_dir = source_code.source_dir
# requirements may be None when SourceCode.requirements is not set;
# get_training_code_hash handles None dependencies gracefully
requirements = source_code.requirements
entry_point = source_code.entry_script
return get_training_code_hash(entry_point, source_dir, requirements)
Expand All @@ -197,6 +199,7 @@ def get_processing_dependencies(dependency_args: List[List[str]]) -> List[str]:


def get_processing_code_hash(code: str, source_dir: str, dependencies: List[str]) -> str:
dependencies = dependencies or []
"""Get the hash of a processing step's code artifact(s).

Args:
Expand Down
57 changes: 57 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,35 @@ def test_get_processing_dependencies_multiple_lists(self):

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

def test_get_processing_code_hash_with_none_dependencies(self):
"""Test get_processing_code_hash does not raise TypeError when dependencies is None"""
with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
f.write("print('hello')")
temp_file = f.name

try:
# Should not raise TypeError
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 source_dir and None dependencies"""
with tempfile.TemporaryDirectory() as temp_dir:
code_file = Path(temp_dir, "script.py")
code_file.write_text("print('hello')")

# Should not raise TypeError
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 +293,34 @@ 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 source_dir and None dependencies does not raise"""
with tempfile.TemporaryDirectory() as temp_dir:
entry_file = Path(temp_dir, "train.py")
entry_file.write_text("print('training')")

# Should not raise TypeError
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 entry_point only and None dependencies does not raise"""
with tempfile.TemporaryDirectory() as temp_dir:
entry_file = Path(temp_dir, "train.py")
entry_file.write_text("print('training')")

# Should not raise TypeError
result = get_training_code_hash(
entry_point=str(entry_file), source_dir=None, dependencies=None
)

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

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