sagemaker-core 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sagemaker-core might be problematic. Click here for more details.
- sagemaker_core-0.1.3/LICENSE +201 -0
- sagemaker_core-0.1.3/MANIFEST.in +1 -0
- sagemaker_core-0.1.3/PKG-INFO +28 -0
- sagemaker_core-0.1.3/README.md +2 -0
- sagemaker_core-0.1.3/VERSION +1 -0
- sagemaker_core-0.1.3/pyproject.toml +46 -0
- sagemaker_core-0.1.3/setup.cfg +11 -0
- sagemaker_core-0.1.3/src/sagemaker_core/__init__.py +0 -0
- sagemaker_core-0.1.3/src/sagemaker_core/_version.py +11 -0
- sagemaker_core-0.1.3/src/sagemaker_core/code_injection/__init__.py +0 -0
- sagemaker_core-0.1.3/src/sagemaker_core/code_injection/base.py +42 -0
- sagemaker_core-0.1.3/src/sagemaker_core/code_injection/codec.py +241 -0
- sagemaker_core-0.1.3/src/sagemaker_core/code_injection/constants.py +18 -0
- sagemaker_core-0.1.3/src/sagemaker_core/code_injection/shape_dag.py +14527 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/__init__.py +0 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/config_schema.py +870 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/exceptions.py +147 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/intelligent_defaults_helper.py +198 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/resources.py +26998 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/shapes.py +11584 -0
- sagemaker_core-0.1.3/src/sagemaker_core/generated/utils.py +314 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/__init__.py +1 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/codegen.py +56 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/constants.py +96 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/data_extractor.py +49 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/method.py +32 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/resources_codegen.py +2122 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/resources_extractor.py +373 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/shapes_codegen.py +284 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/shapes_extractor.py +259 -0
- sagemaker_core-0.1.3/src/sagemaker_core/tools/templates.py +747 -0
- sagemaker_core-0.1.3/src/sagemaker_core/util/__init__.py +0 -0
- sagemaker_core-0.1.3/src/sagemaker_core/util/util.py +81 -0
- sagemaker_core-0.1.3/src/sagemaker_core.egg-info/PKG-INFO +28 -0
- sagemaker_core-0.1.3/src/sagemaker_core.egg-info/SOURCES.txt +37 -0
- sagemaker_core-0.1.3/src/sagemaker_core.egg-info/dependency_links.txt +1 -0
- sagemaker_core-0.1.3/src/sagemaker_core.egg-info/requires.txt +11 -0
- sagemaker_core-0.1.3/src/sagemaker_core.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include VERSION
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: sagemaker-core
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: An python package for sagemaker core functionalities
|
|
5
|
+
Author-email: AWS <sagemaker-interests@amazon.com>
|
|
6
|
+
Project-URL: Repository, https://github.com/aws/sagemaker-core.git
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: boto3<2.0.0,>=1.34.0
|
|
17
|
+
Requires-Dist: pydantic<3.0.0,>=2.7.0
|
|
18
|
+
Requires-Dist: PyYAML<7.0,>=6.0
|
|
19
|
+
Requires-Dist: jsonschema<5.0.0
|
|
20
|
+
Requires-Dist: platformdirs<5.0.0,>=4.0.0
|
|
21
|
+
Provides-Extra: codegen
|
|
22
|
+
Requires-Dist: black<25.0.0,>=24.3.0; extra == "codegen"
|
|
23
|
+
Requires-Dist: pandas<3.0.0,>=2.0.0; extra == "codegen"
|
|
24
|
+
Requires-Dist: pytest<9.0.0,>=8.0.0; extra == "codegen"
|
|
25
|
+
Requires-Dist: pylint<4.0.0,>=3.0.0; extra == "codegen"
|
|
26
|
+
|
|
27
|
+
# sagemaker-code-gen
|
|
28
|
+
Repo for code gen
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.3
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sagemaker-core"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "An python package for sagemaker core functionalities"
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "AWS", email = "sagemaker-interests@amazon.com"}
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
dependencies = [
|
|
14
|
+
# Add your dependencies here (Include lower and upper bounds as applicable)
|
|
15
|
+
"boto3>=1.34.0,<2.0.0",
|
|
16
|
+
"pydantic>=2.7.0,<3.0.0",
|
|
17
|
+
"PyYAML>=6.0, <7.0",
|
|
18
|
+
"jsonschema<5.0.0",
|
|
19
|
+
"platformdirs>=4.0.0, <5.0.0"
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.8"
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: Apache Software License",
|
|
26
|
+
"Programming Language :: Python :: 3.8",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
codegen = [
|
|
33
|
+
"black>=24.3.0, <25.0.0",
|
|
34
|
+
"pandas>=2.0.0, <3.0.0",
|
|
35
|
+
"pytest>=8.0.0, <9.0.0",
|
|
36
|
+
"pylint>=3.0.0, <4.0.0"
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Repository = "https://github.com/aws/sagemaker-core.git"
|
|
41
|
+
|
|
42
|
+
[tool.black]
|
|
43
|
+
line-length = 100
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.dynamic]
|
|
46
|
+
version = { attr = "sagemaker_core._version.__version__"}
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
4
|
+
|
|
5
|
+
# Get the root directory of the project
|
|
6
|
+
root_dir = os.path.abspath(os.path.join(script_dir, "..", ".."))
|
|
7
|
+
|
|
8
|
+
version_file_path = os.path.join(root_dir, "VERSION")
|
|
9
|
+
|
|
10
|
+
with open(version_file_path) as version_file:
|
|
11
|
+
__version__ = version_file.read().strip()
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
import os
|
|
14
|
+
import boto3
|
|
15
|
+
from botocore.config import Config
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Base:
|
|
19
|
+
def __init__(self, session=None, region=None):
|
|
20
|
+
aws_access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
|
|
21
|
+
aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
|
|
22
|
+
aws_session_token = os.getenv("AWS_SESSION_TOKEN")
|
|
23
|
+
profile_name = os.getenv("AWS_PROFILE")
|
|
24
|
+
|
|
25
|
+
if session is None:
|
|
26
|
+
if all([aws_access_key_id, aws_secret_access_key, aws_session_token]):
|
|
27
|
+
self.session = boto3.Session(
|
|
28
|
+
aws_access_key_id=aws_access_key_id,
|
|
29
|
+
aws_secret_access_key=aws_secret_access_key,
|
|
30
|
+
aws_session_token=aws_session_token,
|
|
31
|
+
)
|
|
32
|
+
elif profile_name:
|
|
33
|
+
self.session = boto3.Session(profile_name=profile_name)
|
|
34
|
+
else:
|
|
35
|
+
self.session = boto3.Session()
|
|
36
|
+
|
|
37
|
+
self.region = region if region else os.getenv("AWS_REGION")
|
|
38
|
+
|
|
39
|
+
# Create a custom config with the user agent
|
|
40
|
+
custom_config = Config(region_name=self.region, user_agent_extra="SageMakerSDK/3.0")
|
|
41
|
+
|
|
42
|
+
self.client = self.session.client("sagemaker", config=custom_config)
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
import logging
|
|
14
|
+
|
|
15
|
+
from dataclasses import asdict
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
from sagemaker_core.code_injection.shape_dag import SHAPE_DAG
|
|
19
|
+
from sagemaker_core.code_injection.constants import (
|
|
20
|
+
BASIC_TYPES,
|
|
21
|
+
STRUCTURE_TYPE,
|
|
22
|
+
LIST_TYPE,
|
|
23
|
+
MAP_TYPE,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def pascal_to_snake(pascal_str):
|
|
28
|
+
"""
|
|
29
|
+
Converts a PascalCase string to snake_case.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
pascal_str (str): The PascalCase string to be converted.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
str: The converted snake_case string.
|
|
36
|
+
"""
|
|
37
|
+
snake_case = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", pascal_str)
|
|
38
|
+
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", snake_case).lower()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def deserialize(data, cls) -> object:
|
|
42
|
+
"""
|
|
43
|
+
Deserialize the given data into an instance of the specified class.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
data (dict): The data to be deserialized.
|
|
47
|
+
cls (str or type): The class or class name to deserialize into.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
object: An instance of the specified class with the deserialized data.
|
|
51
|
+
"""
|
|
52
|
+
# Convert the keys to snake_case
|
|
53
|
+
logging.debug(f"Deserialize: pascal cased data: {data}")
|
|
54
|
+
data = {pascal_to_snake(k): v for k, v in data.items()}
|
|
55
|
+
logging.debug(f"Deserialize: snake cased data: {data}")
|
|
56
|
+
|
|
57
|
+
# Get the class from the cls_name string
|
|
58
|
+
if type(cls) == str:
|
|
59
|
+
cls = globals()[cls]
|
|
60
|
+
|
|
61
|
+
# Create a new instance of the class
|
|
62
|
+
instance = cls(**data)
|
|
63
|
+
|
|
64
|
+
return instance
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def snake_to_pascal(snake_str):
|
|
68
|
+
"""
|
|
69
|
+
Convert a snake_case string to PascalCase.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
snake_str (str): The snake_case string to be converted.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
str: The PascalCase string.
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
components = snake_str.split("_")
|
|
79
|
+
return "".join(x.title() for x in components[0:])
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def serialize(data) -> object:
|
|
83
|
+
"""
|
|
84
|
+
Serializes the given data object into a dictionary.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
data: The data object to be serialized.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
A dictionary containing the serialized data.
|
|
91
|
+
|
|
92
|
+
"""
|
|
93
|
+
data_dict = asdict(data)
|
|
94
|
+
|
|
95
|
+
# Convert the keys to pascalCase
|
|
96
|
+
data_dict = {snake_to_pascal(k): v for k, v in data_dict.items() if v is not None}
|
|
97
|
+
|
|
98
|
+
return data_dict
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _evaluate_list_type(raw_list, shape) -> list:
|
|
102
|
+
"""
|
|
103
|
+
Evaluates a list type based on the given shape.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
raw_list (list): The raw list to be evaluated.
|
|
107
|
+
shape (dict): The shape of the list.
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
list: The evaluated list based on the shape.
|
|
111
|
+
|
|
112
|
+
Raises:
|
|
113
|
+
ValueError: If an unhandled list member type is encountered.
|
|
114
|
+
|
|
115
|
+
"""
|
|
116
|
+
_shape_member_type = shape["member_type"]
|
|
117
|
+
_shape_member_shape = shape["member_shape"]
|
|
118
|
+
if _shape_member_type in BASIC_TYPES:
|
|
119
|
+
# if basic types directly assign list value.
|
|
120
|
+
_evaluated_list = raw_list
|
|
121
|
+
elif _shape_member_type == STRUCTURE_TYPE:
|
|
122
|
+
# if structure type transform each list item and assign value.
|
|
123
|
+
_evaluated_list = []
|
|
124
|
+
# traverse through response list and evaluate item
|
|
125
|
+
for item in raw_list:
|
|
126
|
+
_evaluated_item = transform(item, _shape_member_shape)
|
|
127
|
+
_evaluated_list.append(_evaluated_item)
|
|
128
|
+
else:
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"Unhandled List member type "
|
|
131
|
+
f"[{_shape_member_type}] encountered. "
|
|
132
|
+
"Needs additional logic for support"
|
|
133
|
+
)
|
|
134
|
+
return _evaluated_list
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _evaluate_map_type(raw_map, shape) -> dict:
|
|
138
|
+
"""
|
|
139
|
+
Evaluates a map type based on the given shape.
|
|
140
|
+
|
|
141
|
+
Args:
|
|
142
|
+
raw_map (dict): The raw map to be evaluated.
|
|
143
|
+
shape (dict): The shape of the map.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
dict: The evaluated map.
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
ValueError: If an unhandled map key type or list member type is encountered.
|
|
150
|
+
"""
|
|
151
|
+
_shape_key_type = shape["key_type"]
|
|
152
|
+
_shape_value_type = shape["value_type"]
|
|
153
|
+
_shape_value_shape = shape["value_shape"]
|
|
154
|
+
if _shape_key_type != "string":
|
|
155
|
+
raise ValueError(
|
|
156
|
+
f"Unhandled Map key type "
|
|
157
|
+
f"[{_shape_key_type}] encountered. "
|
|
158
|
+
"Needs additional logic for support"
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
_evaluated_map = {}
|
|
162
|
+
if _shape_value_type in BASIC_TYPES:
|
|
163
|
+
# if basic types directly assign value.
|
|
164
|
+
# Ex. response["map_member"] = {"key":"value"}
|
|
165
|
+
_evaluated_map = raw_map
|
|
166
|
+
elif _shape_value_type == STRUCTURE_TYPE:
|
|
167
|
+
# if structure type loop through and evaluate values
|
|
168
|
+
for k, v in raw_map.items():
|
|
169
|
+
_evaluated_value = transform(v, _shape_value_shape)
|
|
170
|
+
_evaluated_map[k] = _evaluated_value
|
|
171
|
+
elif _shape_value_type == LIST_TYPE:
|
|
172
|
+
for k, v in raw_map.items():
|
|
173
|
+
_list_type_shape = SHAPE_DAG[_shape_value_shape]
|
|
174
|
+
evaluated_values = _evaluate_list_type(v, _list_type_shape)
|
|
175
|
+
_evaluated_map[k] = evaluated_values
|
|
176
|
+
elif _shape_value_type == MAP_TYPE:
|
|
177
|
+
for k, v in raw_map.items():
|
|
178
|
+
_map_type_shape = SHAPE_DAG[_shape_value_shape]
|
|
179
|
+
evaluated_values = _evaluate_map_type(v, _map_type_shape)
|
|
180
|
+
_evaluated_map[k] = evaluated_values
|
|
181
|
+
else:
|
|
182
|
+
raise ValueError(
|
|
183
|
+
f"Unhandled List member type "
|
|
184
|
+
f"[{_shape_value_type}] encountered. "
|
|
185
|
+
"Needs additional logic for support"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
return _evaluated_map
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def transform(data, shape, object_instance=None) -> dict:
|
|
192
|
+
"""
|
|
193
|
+
Transforms the given data based on the given shape.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
data (dict): The data to be transformed.
|
|
197
|
+
shape (str): The shape of the data.
|
|
198
|
+
object_instance (object): The object to be transformed. (Optional)
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
dict: The transformed data.
|
|
202
|
+
|
|
203
|
+
Raises:
|
|
204
|
+
ValueError: If an unhandled shape type is encountered.
|
|
205
|
+
"""
|
|
206
|
+
result = {}
|
|
207
|
+
_shape = SHAPE_DAG[shape]
|
|
208
|
+
|
|
209
|
+
if _shape["type"] in BASIC_TYPES:
|
|
210
|
+
raise ValueError("Unexpected low-level operation model shape")
|
|
211
|
+
|
|
212
|
+
for member in _shape["members"]:
|
|
213
|
+
_member_name = member["name"]
|
|
214
|
+
_member_shape = member["shape"]
|
|
215
|
+
_member_type = member["type"]
|
|
216
|
+
if data.get(_member_name) is None:
|
|
217
|
+
# skip members that are not in the response
|
|
218
|
+
continue
|
|
219
|
+
# 1. set snake case attribute name
|
|
220
|
+
attribute_name = pascal_to_snake(_member_name)
|
|
221
|
+
# 2. assign response value
|
|
222
|
+
if _member_type in BASIC_TYPES:
|
|
223
|
+
evaluated_value = data[_member_name]
|
|
224
|
+
elif _member_type == STRUCTURE_TYPE:
|
|
225
|
+
evaluated_value = transform(data[_member_name], _member_shape)
|
|
226
|
+
elif _member_type == LIST_TYPE:
|
|
227
|
+
_list_type_shape = SHAPE_DAG[_member_shape]
|
|
228
|
+
# 2. assign response value
|
|
229
|
+
evaluated_value = _evaluate_list_type(data[_member_name], _list_type_shape)
|
|
230
|
+
elif _member_type == MAP_TYPE:
|
|
231
|
+
_map_type_shape = SHAPE_DAG[_member_shape]
|
|
232
|
+
evaluated_value = _evaluate_map_type(data[_member_name], _map_type_shape)
|
|
233
|
+
else:
|
|
234
|
+
raise ValueError(f"Unexpected member type encountered: {_member_type}")
|
|
235
|
+
|
|
236
|
+
result[attribute_name] = evaluated_value
|
|
237
|
+
if object_instance:
|
|
238
|
+
# 3. set attribute value
|
|
239
|
+
setattr(object_instance, attribute_name, evaluated_value)
|
|
240
|
+
|
|
241
|
+
return result
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
"""Constants used in the code_injection modules."""
|
|
14
|
+
|
|
15
|
+
BASIC_TYPES = ["string", "boolean", "integer", "long", "double", "timestamp", "float"]
|
|
16
|
+
STRUCTURE_TYPE = "structure"
|
|
17
|
+
MAP_TYPE = "map"
|
|
18
|
+
LIST_TYPE = "list"
|