forked from kubeflow/trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen-api.sh
More file actions
executable file
·69 lines (57 loc) · 2.46 KB
/
gen-api.sh
File metadata and controls
executable file
·69 lines (57 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# Copyright 2025 The Kubeflow Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License 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.
# Run this script from the root location: `make generate`
set -o errexit
set -o nounset
# Source container runtime utilities
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/../scripts/container-runtime.sh"
# Setup container runtime
setup_container_runtime
TRAINER_ROOT="$(pwd)"
VERSION_FILE="${TRAINER_ROOT}/VERSION"
if [ ! -f "${VERSION_FILE}" ]; then
echo "Missing VERSION file at ${VERSION_FILE}"
exit 1
fi
API_VERSION=$(sed -e 's/^v//' -e 's/-rc\.\([0-9]*\)/rc\1/' "${VERSION_FILE}")
API_OUTPUT_PATH="api/python_api"
PKG_ROOT="${API_OUTPUT_PATH}/kubeflow_trainer_api"
OPENAPI_GENERATOR_VERSION="v7.13.0"
SWAGGER_CODEGEN_CONF="hack/python-api/swagger_config.json"
SWAGGER_CODEGEN_FILE="api/openapi-spec/swagger.json"
echo "Generating Python API models for Kubeflow Trainer V2 using ${CONTAINER_RUNTIME}..."
# We need to add user to allow container override existing files.
${CONTAINER_RUNTIME} run --user "$(id -u)":"$(id -g)" --rm \
-v "${TRAINER_ROOT}:/local" docker.io/openapitools/openapi-generator-cli:${OPENAPI_GENERATOR_VERSION} generate \
-g python \
-i "local/${SWAGGER_CODEGEN_FILE}" \
-c "local/${SWAGGER_CODEGEN_CONF}" \
-o "local/${API_OUTPUT_PATH}" \
-p=packageVersion="${API_VERSION}" \
--global-property models,modelTests=false,modelDocs=false,supportingFiles=__init__.py
echo "Removing unused files for the Python API"
git clean -f ${API_OUTPUT_PATH}/.openapi-generator
git clean -f ${API_OUTPUT_PATH}/.github
git clean -f ${API_OUTPUT_PATH}/test
git clean -f ${PKG_ROOT}/api
# Revert manually created files.
git checkout ${PKG_ROOT}/__init__.py
# Manually modify the SDK version in the __init__.py file.
if [[ $(uname) == "Darwin" ]]; then
sed -i '' -e "s/__version__.*/__version__ = \"${API_VERSION}\"/" ${PKG_ROOT}/__init__.py
else
sed -i -e "s/__version__.*/__version__ = \"${API_VERSION}\"/" ${PKG_ROOT}/__init__.py
fi