23
23
24
24
25
25
class PropertiesMeta (type ):
26
- """Load an internal shapes attribute from the botocore sagemaker service model."""
26
+ """Load an internal shapes attribute from the botocore service model
27
27
28
- _shapes = None
28
+ for sagemaker and emr service.
29
+ """
30
+
31
+ _shapes_map = dict ()
29
32
_primitive_types = {"string" , "boolean" , "integer" , "float" }
30
33
31
34
def __new__ (mcs , * args , ** kwargs ):
32
- """Loads up the shapes from the botocore sagemaker service model."""
33
- if mcs ._shapes is None :
35
+ """Loads up the shapes from the botocore service model."""
36
+ if len ( mcs ._shapes_map . keys ()) == 0 :
34
37
loader = botocore .loaders .Loader ()
35
- model = loader .load_service_model ("sagemaker" , "service-2" )
36
- mcs ._shapes = model ["shapes" ]
38
+
39
+ sagemaker_model = loader .load_service_model ("sagemaker" , "service-2" )
40
+ emr_model = loader .load_service_model ("emr" , "service-2" )
41
+ mcs ._shapes_map ["sagemaker" ] = sagemaker_model ["shapes" ]
42
+ mcs ._shapes_map ["emr" ] = emr_model ["shapes" ]
43
+
37
44
return super ().__new__ (mcs , * args , ** kwargs )
38
45
39
46
@@ -45,32 +52,41 @@ def __init__(
45
52
path : str ,
46
53
shape_name : str = None ,
47
54
shape_names : List [str ] = None ,
55
+ service_name : str = "sagemaker" ,
48
56
):
49
57
"""Create a Properties instance representing the given shape.
50
58
51
59
Args:
52
60
path (str): The parent path of the Properties instance.
53
- shape_name (str): The botocore sagemaker service model shape name.
54
- shape_names (str): A List of the botocore sagemaker service model shape name.
61
+ shape_name (str): The botocore service model shape name.
62
+ shape_names (str): A List of the botocore service model shape name.
55
63
"""
56
64
self ._path = path
57
65
shape_names = [] if shape_names is None else shape_names
58
66
self ._shape_names = shape_names if shape_name is None else [shape_name ] + shape_names
59
67
68
+ shapes = Properties ._shapes_map .get (service_name , {})
69
+
60
70
for name in self ._shape_names :
61
- shape = Properties . _shapes .get (name , {})
71
+ shape = shapes .get (name , {})
62
72
shape_type = shape .get ("type" )
63
73
if shape_type in Properties ._primitive_types :
64
74
self .__str__ = name
65
75
elif shape_type == "structure" :
66
76
members = shape ["members" ]
67
77
for key , info in members .items ():
68
- if Properties ._shapes .get (info ["shape" ], {}).get ("type" ) == "list" :
69
- self .__dict__ [key ] = PropertiesList (f"{ path } .{ key } " , info ["shape" ])
70
- elif Properties ._shapes .get (info ["shape" ], {}).get ("type" ) == "map" :
71
- self .__dict__ [key ] = PropertiesMap (f"{ path } .{ key } " , info ["shape" ])
78
+ if shapes .get (info ["shape" ], {}).get ("type" ) == "list" :
79
+ self .__dict__ [key ] = PropertiesList (
80
+ f"{ path } .{ key } " , info ["shape" ], service_name
81
+ )
82
+ elif shapes .get (info ["shape" ], {}).get ("type" ) == "map" :
83
+ self .__dict__ [key ] = PropertiesMap (
84
+ f"{ path } .{ key } " , info ["shape" ], service_name
85
+ )
72
86
else :
73
- self .__dict__ [key ] = Properties (f"{ path } .{ key } " , info ["shape" ])
87
+ self .__dict__ [key ] = Properties (
88
+ f"{ path } .{ key } " , info ["shape" ], service_name = service_name
89
+ )
74
90
75
91
@property
76
92
def expr (self ):
@@ -81,16 +97,17 @@ def expr(self):
81
97
class PropertiesList (Properties ):
82
98
"""PropertiesList for use in workflow expressions."""
83
99
84
- def __init__ (self , path : str , shape_name : str = None ):
100
+ def __init__ (self , path : str , shape_name : str = None , service_name : str = "sagemaker" ):
85
101
"""Create a PropertiesList instance representing the given shape.
86
102
87
103
Args:
88
104
path (str): The parent path of the PropertiesList instance.
89
- shape_name (str): The botocore sagemaker service model shape name.
90
- root_shape_name (str): The botocore sagemaker service model shape name.
105
+ shape_name (str): The botocore service model shape name.
106
+ service_name (str): The botocore service name.
91
107
"""
92
108
super (PropertiesList , self ).__init__ (path , shape_name )
93
109
self .shape_name = shape_name
110
+ self .service_name = service_name
94
111
self ._items : Dict [Union [int , str ], Properties ] = dict ()
95
112
96
113
def __getitem__ (self , item : Union [int , str ]):
@@ -100,7 +117,7 @@ def __getitem__(self, item: Union[int, str]):
100
117
item (Union[int, str]): The index of the item in sequence.
101
118
"""
102
119
if item not in self ._items .keys ():
103
- shape = Properties ._shapes .get (self .shape_name )
120
+ shape = Properties ._shapes_map . get ( self . service_name , {}) .get (self .shape_name )
104
121
member = shape ["member" ]["shape" ]
105
122
if isinstance (item , str ):
106
123
property_item = Properties (f"{ self ._path } ['{ item } ']" , member )
@@ -114,15 +131,17 @@ def __getitem__(self, item: Union[int, str]):
114
131
class PropertiesMap (Properties ):
115
132
"""PropertiesMap for use in workflow expressions."""
116
133
117
- def __init__ (self , path : str , shape_name : str = None ):
134
+ def __init__ (self , path : str , shape_name : str = None , service_name : str = "sagemaker" ):
118
135
"""Create a PropertiesMap instance representing the given shape.
119
136
120
137
Args:
121
138
path (str): The parent path of the PropertiesMap instance.
122
139
shape_name (str): The botocore sagemaker service model shape name.
140
+ service_name (str): The botocore service name.
123
141
"""
124
142
super (PropertiesMap , self ).__init__ (path , shape_name )
125
143
self .shape_name = shape_name
144
+ self .service_name = service_name
126
145
self ._items : Dict [Union [int , str ], Properties ] = dict ()
127
146
128
147
def __getitem__ (self , item : Union [int , str ]):
@@ -132,7 +151,7 @@ def __getitem__(self, item: Union[int, str]):
132
151
item (Union[int, str]): The index of the item in sequence.
133
152
"""
134
153
if item not in self ._items .keys ():
135
- shape = Properties ._shapes .get (self .shape_name )
154
+ shape = Properties ._shapes_map . get ( self . service_name , {}) .get (self .shape_name )
136
155
member = shape ["value" ]["shape" ]
137
156
if isinstance (item , str ):
138
157
property_item = Properties (f"{ self ._path } ['{ item } ']" , member )
0 commit comments