sagemaker.core.tools.shapes_codegen#
A class for generating class structure from Service Model JSON.
To run the script be sure to set the PYTHONPATH export PYTHONPATH=<sagemaker-code-gen repo directory>:$PYTHONPATH
Classes
Generates shape classes based on an input Botocore service.json. |
- class sagemaker.core.tools.shapes_codegen.ShapesCodeGen[source]#
Bases:
objectGenerates shape classes based on an input Botocore service.json.
- Parameters:
service_json (dict) – The Botocore service.json containing the shape definitions.
- service_json#
The Botocore service.json containing the shape definitions.
- Type:
dict
- shapes_extractor#
An instance of the ShapesExtractor class.
- Type:
- shape_dag#
Shape DAG generated from service.json
- Type:
dict
- build_graph()[source]#
Builds a directed acyclic graph (DAG) representing the dependencies between shapes.
- topological_sort()[source]#
Performs a topological sort on the DAG to determine the order in which shapes should be generated.
- _filter_input_output_shapes(shape)[source]#
Filters out shapes that are used as input or output for operations.
- generate_shapes(output_folder)[source]#
Generates the shape classes and writes them to the specified output folder.
- build_graph()[source]#
Builds a directed acyclic graph (DAG) representing the dependencies between shapes.
Steps: 1. Loop over the Service Json shapes.
- 1.1. If dependency(members) found, add association of node -> dependency.
- 1.1.1. Sometimes members are not shape themselves, but have associated links to actual shapes.
- In that case add link to node -> dependency (actual)
CreateExperimentRequest -> [ExperimentEntityName, ExperimentDescription, TagList]
1.2. else leaf node found (no dependent members), add association of node -> None.
- Returns:
A dict which defines the structure of the DAG in the format: {key : [dependencies]} Example input:
- {‘CreateExperimentRequest’: [‘ExperimentEntityName’, ‘ExperimentEntityName’,
’ExperimentDescription’, ‘TagList’],
’CreateExperimentResponse’: [‘ExperimentArn’], ‘DeleteExperimentRequest’: [‘ExperimentEntityName’], ‘DeleteExperimentResponse’: [‘ExperimentArn’]}
- generate_base_class()[source]#
Generates the base class for the shape classes.
- Returns:
The generated base class as a string.
- generate_data_class_for_shape(shape)[source]#
Generates a data class for a given shape.
- Parameters:
shape – The name of the shape.
- Returns:
The generated data class as a string.
- generate_imports()[source]#
Generates the import statements for the generated shape classes.
- Returns:
The generated import statements as a string.
- generate_license()[source]#
Generates the license string.
- Returns:
The license string.
- Return type:
str
- generate_shapes(output_folder='/home/docs/checkouts/readthedocs.org/user_builds/sagemaker/checkouts/5737/docs/src/sagemaker/core', file_name='shapes.py') None[source]#
Generates the shape classes and writes them to the specified output folder.
- Parameters:
output_folder – The path to the output folder.