# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # SPDX-License-Identifier: MIT-0 # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # software and associated documentation files (the "Software"), to deal in the Software # without restriction, including without limitation the rights to use, copy, modify, # merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # © 2021 Amazon Web Services, Inc. or its affiliates. All Rights Reserved. This # AWS Content is provided subject to the terms of the AWS Customer Agreement # available at http://aws.amazon.com/agreement or other written agreement between # Customer and either Amazon Web Services, Inc. or Amazon Web Services EMEA SARL # or both. # # Any code, applications, scripts, templates, proofs of concept, documentation # and other items provided by AWS under this SOW are "AWS Content," as defined # in the Agreement, and are provided for illustration purposes only. All such # AWS Content is provided solely at the option of AWS, and is subject to the # terms of the Addendum and the Agreement. Customer is solely responsible for # using, deploying, testing, and supporting any code and applications provided # by AWS under this SOW. # Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of # the License is located at # # http://aws.amazon.com/apache2.0/ # # or in the "license" file accompanying this file. This file is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. """Provides utilities for SageMaker Pipeline CLI.""" from __future__ import absolute_import import ast def get_pipeline_driver(module_name, passed_args=None): """Gets the driver for generating your pipeline definition. Pipeline modules must define a get_pipeline() module-level method. Args: module_name: The module name of your pipeline. passed_args: Optional passed arguments that your pipeline may be templated by. Returns: The SageMaker Workflow pipeline. """ _imports = __import__(module_name, fromlist=["get_pipeline"]) kwargs = convert_struct(passed_args) return _imports.get_pipeline(**kwargs) def convert_struct(str_struct=None): """convert the string argument to it's proper type Args: str_struct (str, optional): string to be evaluated. Defaults to None. Returns: string struct as it's actuat evaluated type """ return ast.literal_eval(str_struct) if str_struct else {} def get_pipeline_custom_tags(module_name, args, tags): """Gets the custom tags for pipeline Returns: Custom tags to be added to the pipeline """ try: _imports = __import__(module_name, fromlist=["get_pipeline_custom_tags"]) kwargs = convert_struct(args) return _imports.get_pipeline_custom_tags(tags, kwargs["region"], kwargs["sagemaker_project_arn"]) except Exception as e: print(f"Error getting project tags: {e}") return tags