Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [
readme = "README.rst"
dependencies = [
# Add your dependencies here (Include lower and upper bounds as applicable)
"boto3>=1.34.0,<2.0.0",
"boto3>=1.35.75,<2.0.0",
"pydantic>=2.0.0,<3.0.0",
"PyYAML>=6.0, <7.0",
"jsonschema<5.0.0",
Expand Down
18 changes: 16 additions & 2 deletions src/sagemaker_core/main/code_injection/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,30 @@ def _evaluate_list_type(raw_list, shape) -> list:
"""
_shape_member_type = shape["member_type"]
_shape_member_shape = shape["member_shape"]
_evaluated_list = []
if _shape_member_type in BASIC_TYPES:
# if basic types directly assign list value.
_evaluated_list = raw_list
elif _shape_member_type == STRUCTURE_TYPE:
# if structure type transform each list item and assign value.
_evaluated_list = []
# if structure type, transform each list item and assign value.
# traverse through response list and evaluate item
for item in raw_list:
_evaluated_item = transform(item, _shape_member_shape)
_evaluated_list.append(_evaluated_item)
elif _shape_member_type == LIST_TYPE:
# if list type, transform each list item and assign value.
# traverse through response list and evaluate item
for item in raw_list:
_list_type_shape = SHAPE_DAG[_shape_member_shape]
_evaluated_item = _evaluate_list_type(item, _list_type_shape)
_evaluated_list.append(_evaluated_item)
elif _shape_member_type == MAP_TYPE:
# if structure type, transform each list item and assign value.
# traverse through response list and evaluate item
for item in raw_list:
_map_type_shape = SHAPE_DAG[_shape_member_shape]
_evaluated_item = _evaluate_map_type(item, _map_type_shape)
_evaluated_list.append(_evaluated_item)
else:
raise ValueError(
f"Unhandled List member type "
Expand Down
5 changes: 3 additions & 2 deletions src/sagemaker_core/tools/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def get_docstring_title(self, operation):
title = remove_html_tags(operation["documentation"])
self.docstring_title = title.split(".")[0] + "."
documentation = operation.get("documentation")
title = remove_html_tags(documentation) if documentation else None
self.docstring_title = title.split(".")[0] + "." if title else None

# TODO: add some templates for common methods
9 changes: 7 additions & 2 deletions src/sagemaker_core/tools/resources_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,15 +931,20 @@ def _fetch_shape_errors_and_doc_strings(self, operation):
for e in errors:
error_shape = e["shape"]
error_shape_dict = self.shapes[error_shape]
error_shape_documentation = error_shape_dict.get("documentation").strip()
error_shape_documentation = error_shape_dict.get("documentation")
if error_shape_documentation:
error_shape_documentation.strip()
shape_errors_and_docstrings[error_shape] = error_shape_documentation
sorted_keys = sorted(shape_errors_and_docstrings.keys())
return {key: shape_errors_and_docstrings[key] for key in sorted_keys}

def _exception_docstring(self, operation: str) -> str:
_docstring = RESOURCE_METHOD_EXCEPTION_DOCSTRING
for error, documentaion in self._fetch_shape_errors_and_doc_strings(operation).items():
_docstring += f"\n {error}: {remove_html_tags(documentaion).strip()}"
if documentaion:
_docstring += f"\n {error}: {remove_html_tags(documentaion).strip()}"
else:
_docstring += f"\n {error}"
return _docstring

def _generate_docstring(
Expand Down
19 changes: 12 additions & 7 deletions src/sagemaker_core/tools/shapes_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,24 @@ def get_shapes_dag(self):

def _evaluate_list_type(self, member_shape):
list_shape_name = member_shape["member"]["shape"]
list_shape_type = self.combined_shapes[list_shape_name]["type"]
if list_shape_type in ["list", "map"]:
raise Exception(
"Unhandled list shape key type encountered, needs extra logic to handle this"
)
if list_shape_type == "structure":
list_shape_member = self.combined_shapes[list_shape_name]
list_shape_type = list_shape_member["type"]
if list_shape_type == "list":
member_type = f"List[{self._evaluate_list_type(list_shape_member)}]"
elif list_shape_type == "map":
member_type = f"List[{self._evaluate_map_type(list_shape_member)}]"
elif list_shape_type == "structure":
# handling an edge case of nested structure
if list_shape_name == "SearchExpression":
member_type = f"List['{list_shape_name}']"
else:
member_type = f"List[{list_shape_name}]"
else:
elif list_shape_type in BASIC_JSON_TYPES_TO_PYTHON_TYPES.keys():
member_type = f"List[{BASIC_JSON_TYPES_TO_PYTHON_TYPES[list_shape_type]}]"
else:
raise Exception(
f"Unhandled list shape key type {list_shape_type} for Shape: {list_shape_name} encountered, needs extra logic to handle this"
)
return member_type

def _evaluate_map_type(self, member_shape):
Expand Down
Loading