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.

Can you add a comment over your source code changes explaining why you default to []?

Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ 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
"""

dependencies = dependencies or []


# FrameworkProcessor
if source_dir:
source_dir_url = urlparse(source_dir)
Expand Down Expand Up @@ -245,6 +248,9 @@ def get_training_code_hash(
Returns:
str: A hash string representing the unique code artifact(s) for the step
"""
dependencies = dependencies or []


from sagemaker.core.workflow import is_pipeline_variable

if not is_pipeline_variable(source_dir) and not is_pipeline_variable(entry_point):
Expand Down
58 changes: 58 additions & 0 deletions sagemaker-core/tests/unit/workflow/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,64 @@ def test_get_training_code_hash_pipeline_variable(self):

assert result is None

def test_get_training_code_hash_with_none_dependencies_source_dir(self):
"""Test get_training_code_hash with source_dir and dependencies=None does not raise TypeError"""
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_entry_point_only_and_none_dependencies(self):
"""Test get_training_code_hash with entry_point only and dependencies=None returns valid hash"""
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_processing_code_hash_with_none_dependencies_source_dir(self):
"""Test get_processing_code_hash with source_dir and dependencies=None does not raise TypeError"""
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_none_dependencies_code_only(self):
"""Test get_processing_code_hash with code only and dependencies=None does not raise TypeError"""
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_validate_step_args_input_valid(self):
"""Test validate_step_args_input with valid input"""
step_args = _StepArguments(
Expand Down
Loading