Skip to content

Commit b02d710

Browse files
authored
added python-aio.sh to generate kubernetes asyncio client with kuberentes_aio path (#301)
1 parent 04e8d96 commit b02d710

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

openapi/python-aio.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
# Copyright 2018 The Kubernetes 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+
ARGC=$#
22+
23+
if [ $# -ne 2 ]; then
24+
echo "Usage:"
25+
echo " python-aio.sh OUTPUT_DIR SETTING_FILE_PATH"
26+
echo " Setting file should define KUBERNETES_BRANCH, CLIENT_VERSION, and PACKAGE_NAME"
27+
exit 1
28+
fi
29+
30+
31+
OUTPUT_DIR=$1
32+
SETTING_FILE=$2
33+
mkdir -p "${OUTPUT_DIR}"
34+
35+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")
36+
pushd "${SCRIPT_ROOT}" > /dev/null
37+
SCRIPT_ROOT=`pwd`
38+
popd > /dev/null
39+
40+
pushd "${OUTPUT_DIR}" > /dev/null
41+
OUTPUT_DIR=`pwd`
42+
popd > /dev/null
43+
44+
source "${SETTING_FILE}"
45+
46+
# use openapi-generator to generate library
47+
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
48+
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v6.6.0}"
49+
50+
CLIENT_LANGUAGE=python-asyncio
51+
CLEANUP_DIRS=(client/apis client/models docs test)
52+
kubeclient::generator::generate_client "${OUTPUT_DIR}"
53+
54+
# Generic patches to the generated Python code, most notably renaming the library.
55+
echo "--- Patching generated code..."
56+
57+
if [ ${PACKAGE_NAME} == "client" ]; then
58+
59+
# Post-processing of the generated Python wrapper.
60+
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i 's/\bclient/kubernetes_aio.client/g' {} +
61+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/\bclient/kubernetes_aio.client/g' {} +
62+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/kubernetes_aio.client-python/client-python/g' {} +
63+
64+
# fix imports
65+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_aio.client./g' {} +
66+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes_aio.client/g' {} +
67+
find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes_aio.client.models/g' {} +
68+
69+
else
70+
71+
# Post-processing of the generated Python wrapper.
72+
find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
73+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/\\bclient/${PACKAGE_NAME}.client/g" {} +
74+
find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i "s/${PACKAGE_NAME}.client-python/client-python/g" {} +
75+
76+
fi
77+
78+
echo "---Done."

0 commit comments

Comments
 (0)