|
16 | 16 | import abc |
17 | 17 |
|
18 | 18 | from enum import EnumMeta |
19 | | -from typing import Any, Dict, List, Union |
| 19 | +from typing import Any, Dict, List, Union, Optional |
20 | 20 |
|
21 | 21 | PrimitiveType = Union[str, int, bool, float, None] |
22 | 22 | RequestType = Union[Dict[str, Any], List[Dict[str, Any]]] |
@@ -57,3 +57,80 @@ class Expression(abc.ABC): |
57 | 57 | @abc.abstractmethod |
58 | 58 | def expr(self) -> RequestType: |
59 | 59 | """Get the expression structure for workflow service calls.""" |
| 60 | + |
| 61 | + |
| 62 | +class PipelineVariable(Expression): |
| 63 | + """Base object for pipeline variables |
| 64 | +
|
| 65 | + PipelineVariables must implement the expr property. |
| 66 | + """ |
| 67 | + |
| 68 | + def __add__(self, other: Union[Expression, PrimitiveType]): |
| 69 | + """Add function for PipelineVariable |
| 70 | +
|
| 71 | + Args: |
| 72 | + other (Union[Expression, PrimitiveType]): The other object to be concatenated. |
| 73 | +
|
| 74 | + Always raise an error since pipeline variables do not support concatenation |
| 75 | + """ |
| 76 | + |
| 77 | + raise TypeError("Pipeline variables do not support concatenation.") |
| 78 | + |
| 79 | + def __str__(self): |
| 80 | + """Override built-in String function for PipelineVariable""" |
| 81 | + raise TypeError("Pipeline variables do not support __str__ operation.") |
| 82 | + |
| 83 | + def __int__(self): |
| 84 | + """Override built-in Integer function for PipelineVariable""" |
| 85 | + raise TypeError("Pipeline variables do not support __int__ operation.") |
| 86 | + |
| 87 | + def __float__(self): |
| 88 | + """Override built-in Float function for PipelineVariable""" |
| 89 | + raise TypeError("Pipeline variables do not support __float__ operation.") |
| 90 | + |
| 91 | + def to_string(self): |
| 92 | + """Prompt the pipeline to convert the pipeline variable to String in runtime""" |
| 93 | + from sagemaker.workflow.functions import Join |
| 94 | + |
| 95 | + return Join(on="", values=[self]) |
| 96 | + |
| 97 | + @property |
| 98 | + @abc.abstractmethod |
| 99 | + def expr(self) -> RequestType: |
| 100 | + """Get the expression structure for workflow service calls.""" |
| 101 | + |
| 102 | + def startswith( |
| 103 | + self, |
| 104 | + prefix: Union[str, tuple], # pylint: disable=unused-argument |
| 105 | + start: Optional[int] = None, # pylint: disable=unused-argument |
| 106 | + end: Optional[int] = None, # pylint: disable=unused-argument |
| 107 | + ) -> bool: |
| 108 | + """Simulate the Python string's built-in method: startswith |
| 109 | +
|
| 110 | + Args: |
| 111 | + prefix (str, tuple): The (tuple of) string to be checked. |
| 112 | + start (int): To set the start index of the matching boundary (default: None). |
| 113 | + end (int): To set the end index of the matching boundary (default: None). |
| 114 | +
|
| 115 | + Return: |
| 116 | + bool: Always return False as Pipeline variables are parsed during execution runtime |
| 117 | + """ |
| 118 | + return False |
| 119 | + |
| 120 | + def endswith( |
| 121 | + self, |
| 122 | + suffix: Union[str, tuple], # pylint: disable=unused-argument |
| 123 | + start: Optional[int] = None, # pylint: disable=unused-argument |
| 124 | + end: Optional[int] = None, # pylint: disable=unused-argument |
| 125 | + ) -> bool: |
| 126 | + """Simulate the Python string's built-in method: endswith |
| 127 | +
|
| 128 | + Args: |
| 129 | + suffix (str, tuple): The (tuple of) string to be checked. |
| 130 | + start (int): To set the start index of the matching boundary (default: None). |
| 131 | + end (int): To set the end index of the matching boundary (default: None). |
| 132 | +
|
| 133 | + Return: |
| 134 | + bool: Always return False as Pipeline variables are parsed during execution runtime |
| 135 | + """ |
| 136 | + return False |
0 commit comments