Skip to content

Commit e3579c5

Browse files
authored
Merge branch 'master' into accept-step-object-in-dependson-list
2 parents 65f9426 + 5c8ef31 commit e3579c5

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

doc/workflows/pipelines/sagemaker.workflow.pipelines.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ ConditionStep
55
-------------
66

77
.. autoclass:: sagemaker.workflow.condition_step.ConditionStep
8-
.. autoclass:: sagemaker.workflow.condition_step.JsonGet
8+
9+
.. deprecated:: sagemaker.workflow.condition_step.JsonGet
910

1011
Conditions
1112
----------
@@ -53,6 +54,8 @@ Functions
5354

5455
.. autoclass:: sagemaker.workflow.functions.Join
5556

57+
.. autoclass:: sagemaker.workflow.functions.JsonGet
58+
5659
Parameters
5760
----------
5861

src/sagemaker/workflow/condition_step.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import attr
1919

20+
from sagemaker.deprecations import deprecated_class
2021
from sagemaker.workflow.conditions import Condition
2122
from sagemaker.workflow.steps import (
2223
Step,
@@ -114,3 +115,6 @@ def expr(self):
114115
"Path": self.json_path,
115116
}
116117
}
118+
119+
120+
JsonGet = deprecated_class(JsonGet, "JsonGet")

src/sagemaker/workflow/functions.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"""The step definitions for workflow."""
1414
from __future__ import absolute_import
1515

16-
from typing import List
16+
from typing import List, Union
1717

1818
import attr
1919

2020
from sagemaker.workflow.entities import Expression
21+
from sagemaker.workflow.properties import PropertyFile
2122

2223

2324
@attr.s
@@ -54,3 +55,36 @@ def expr(self):
5455
],
5556
},
5657
}
58+
59+
60+
@attr.s
61+
class JsonGet(Expression):
62+
"""Get JSON properties from PropertyFiles.
63+
64+
Attributes:
65+
step_name (str): The step name from which to get the property file.
66+
property_file (Union[PropertyFile, str]): Either a PropertyFile instance
67+
or the name of a property file.
68+
json_path (str): The JSON path expression to the requested value.
69+
"""
70+
71+
step_name: str = attr.ib()
72+
property_file: Union[PropertyFile, str] = attr.ib()
73+
json_path: str = attr.ib()
74+
75+
@property
76+
def expr(self):
77+
"""The expression dict for a `JsonGet` function."""
78+
if not isinstance(self.step_name, str):
79+
raise ValueError("Please give step name as a string")
80+
81+
if isinstance(self.property_file, PropertyFile):
82+
name = self.property_file.name
83+
else:
84+
name = self.property_file
85+
return {
86+
"Std:JsonGet": {
87+
"PropertyFile": {"Get": f"Steps.{self.step_name}.PropertyFiles.{name}"},
88+
"Path": self.json_path,
89+
}
90+
}

tests/unit/sagemaker/workflow/test_functions.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
from __future__ import absolute_import
1515

1616
from sagemaker.workflow.execution_variables import ExecutionVariables
17-
from sagemaker.workflow.functions import Join
17+
from sagemaker.workflow.functions import Join, JsonGet
1818
from sagemaker.workflow.parameters import (
1919
ParameterFloat,
2020
ParameterInteger,
2121
ParameterString,
2222
)
23-
from sagemaker.workflow.properties import Properties
23+
from sagemaker.workflow.properties import Properties, PropertyFile
2424

2525

2626
def test_join_primitives_default_on():
@@ -66,3 +66,34 @@ def test_join_expressions():
6666
],
6767
},
6868
}
69+
70+
71+
def test_json_get_expressions():
72+
73+
assert JsonGet(
74+
step_name="my-step",
75+
property_file="my-property-file",
76+
json_path="my-json-path",
77+
).expr == {
78+
"Std:JsonGet": {
79+
"PropertyFile": {"Get": "Steps.my-step.PropertyFiles.my-property-file"},
80+
"Path": "my-json-path",
81+
},
82+
}
83+
84+
property_file = PropertyFile(
85+
name="name",
86+
output_name="result",
87+
path="output",
88+
)
89+
90+
assert JsonGet(
91+
step_name="my-step",
92+
property_file=property_file,
93+
json_path="my-json-path",
94+
).expr == {
95+
"Std:JsonGet": {
96+
"PropertyFile": {"Get": "Steps.my-step.PropertyFiles.name"},
97+
"Path": "my-json-path",
98+
},
99+
}

0 commit comments

Comments
 (0)