github.com/kubeflow/training-operator@v1.7.0/hack/python-sdk/gen-sdk.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2021 The Kubeflow Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  repo_root="$(dirname "${BASH_SOURCE}")/../.."
    22  
    23  SWAGGER_JAR_URL="https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/4.3.1/openapi-generator-cli-4.3.1.jar"
    24  SWAGGER_CODEGEN_JAR="${repo_root}/hack/python-sdk/openapi-generator-cli.jar"
    25  SWAGGER_CODEGEN_CONF="${repo_root}/hack/python-sdk/swagger_config.json"
    26  SDK_OUTPUT_PATH="${repo_root}/sdk/python"
    27  VERSION=1.7.0
    28  SWAGGER_CODEGEN_FILE="${repo_root}/hack/python-sdk/swagger.json"
    29  
    30  if [ -z "${GOPATH:-}" ]; then
    31    export GOPATH=$(go env GOPATH)
    32  fi
    33  
    34  echo "Generating OpenAPI specification ..."
    35  echo "./hack/update-codegen.sh already help us generate openapi specs ..."
    36  
    37  if [[ ! -f "$SWAGGER_CODEGEN_JAR" ]]; then
    38    echo "Downloading the swagger-codegen JAR package ..."
    39    wget -O "${SWAGGER_CODEGEN_JAR}" ${SWAGGER_JAR_URL}
    40  fi
    41  
    42  echo "Generating swagger file ..."
    43  go run "${repo_root}"/hack/swagger/main.go ${VERSION} >"${SWAGGER_CODEGEN_FILE}"
    44  
    45  echo "Removing previously generated files ..."
    46  rm -rf "${SDK_OUTPUT_PATH}"/docs/V1*.md "${SDK_OUTPUT_PATH}"/kubeflow/training/models "${SDK_OUTPUT_PATH}"/kubeflow/training/*.py "${SDK_OUTPUT_PATH}"/test/test_*.py
    47  echo "Generating Python SDK for Training Operator ..."
    48  java -jar "${SWAGGER_CODEGEN_JAR}" generate -i "${repo_root}"/hack/python-sdk/swagger.json -g python -o "${SDK_OUTPUT_PATH}" -c "${SWAGGER_CODEGEN_CONF}"
    49  
    50  echo "Kubeflow Training Operator Python SDK is generated successfully to folder ${SDK_OUTPUT_PATH}/."
    51  
    52  echo "Running post-generation script ..."
    53  "${repo_root}"/hack/python-sdk/post_gen.py