From a9934498b20aa16cde7fa84d6e4bcddf14ad4963 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Tue, 10 Apr 2018 00:49:31 +0200 Subject: [PATCH 1/4] feat: package named kubernetes_asyncio --- openapi/python-asyncio.sh | 71 ++++++++++++++++++++++++++++++++++++++ openapi/python-asyncio.xml | 55 +++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100755 openapi/python-asyncio.sh create mode 100644 openapi/python-asyncio.xml diff --git a/openapi/python-asyncio.sh b/openapi/python-asyncio.sh new file mode 100755 index 0000000..49530b3 --- /dev/null +++ b/openapi/python-asyncio.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Copyright 2017 The Kubernetes 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. + +set -o errexit +set -o nounset +set -o pipefail + +ARGC=$# + +if [ $# -ne 2 ]; then + echo "Usage:" + echo " python.sh OUTPUT_DIR SETTING_FILE_PATH" + echo " Setting file should define KUBERNETES_BRANCH, CLIENT_VERSION, and PACKAGE_NAME" + exit 1 +fi + + +OUTPUT_DIR=$1 +SETTING_FILE=$2 +mkdir -p "${OUTPUT_DIR}" + +SCRIPT_ROOT=$(dirname "${BASH_SOURCE}") +pushd "${SCRIPT_ROOT}" > /dev/null +SCRIPT_ROOT=`pwd` +popd > /dev/null + +pushd "${OUTPUT_DIR}" > /dev/null +OUTPUT_DIR=`pwd` +popd > /dev/null + +source "${SCRIPT_ROOT}/client-generator.sh" +source "${SETTING_FILE}" + +# SWAGGER_CODEGEN_COMMIT=d2b91073e1fc499fea67141ff4c17740d25f8e83; \ +SWAGGER_CODEGEN_COMMIT=f9b2839a3076f26db1b8fc61655a26662f2552ee; \ +CLIENT_LANGUAGE=python-asyncio; \ +CLEANUP_DIRS=(client/apis client/models docs test); \ +kubeclient::generator::generate_client "${OUTPUT_DIR}" + +echo "--- Patching generated code..." +find "${OUTPUT_DIR}/test" -type f -name \*.py -exec sed -i 's/\bclient/kubernetes_asyncio.client/g' {} + +find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/\bclient/kubernetes_asyncio.client/g' {} + +find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md -exec sed -i 's/kubernetes_asyncio.client-python/client-python/g' {} + + +# workaround https://github.com/swagger-api/swagger-codegen/pull/7905 +find "${OUTPUT_DIR}/client" -type f -name \*.py ! -name '__init__.py' -exec sed -i '/^from .*models.*/d' {} \; + +# +find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_asyncio.client./g' {} + +find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes_asyncio.client/g' {} + +find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes_asyncio.client.models/g' {} + + +#find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client\./from kubernetes.client./g' {} + +#find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client import /from kubernetes.client import /g' {} + + + + +echo "---Done." diff --git a/openapi/python-asyncio.xml b/openapi/python-asyncio.xml new file mode 100644 index 0000000..44a6bff --- /dev/null +++ b/openapi/python-asyncio.xml @@ -0,0 +1,55 @@ + + 4.0.0 + io.kubernetes + client-python + 1.0-SNAPSHOT + client-python + http://kubernetes.io + + + + io.swagger + swagger-codegen-maven-plugin + ${swagger-codegen-version} + + + + generate + + + ${generator.spec.path} + python + asyncio + kubernetes-client + python + + ${generator.package.name} + ${generator.client.version} + true + + ${generator.output.path} + + + + + + + + + + io.swagger + swagger-annotations + ${swagger-annotations-version} + + + + 1.5.0 + 1.0.0 + + + . + swagger.json + swagger_client + unversioned + + From 0ea9fcb058fdbfdb93f4510ca51263fd40a2cf9c Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Fri, 18 May 2018 00:07:06 +0200 Subject: [PATCH 2/4] feat: fix rest client --- openapi/python-asyncio.sh | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/openapi/python-asyncio.sh b/openapi/python-asyncio.sh index 49530b3..50bbdb0 100755 --- a/openapi/python-asyncio.sh +++ b/openapi/python-asyncio.sh @@ -58,14 +58,37 @@ find "${OUTPUT_DIR}" -path "${OUTPUT_DIR}/base" -prune -o -type f -a -name \*.md # workaround https://github.com/swagger-api/swagger-codegen/pull/7905 find "${OUTPUT_DIR}/client" -type f -name \*.py ! -name '__init__.py' -exec sed -i '/^from .*models.*/d' {} \; -# +# workaround https://github.com/swagger-api/swagger-codegen/pull/8204 +# + closing session +echo '21a22,23 +> import asyncio +> +81a84,86 +> def __del__(self): +> asyncio.ensure_future(self.pool_manager.close()) +> +164c169,171 +< async with self.pool_manager.request(**args) as r: +--- +> r = await self.pool_manager.request(**args) +> if _preload_content: +> +168,169c175,176 +< # log response body +< logger.debug("response body: %s", r.data) +--- +> # log response body +> logger.debug("response body: %s", r.data) +171,172c178,179 +< if not 200 <= r.status <= 299: +< raise ApiException(http_resp=r) +--- +> if not 200 <= r.status <= 299: +> raise ApiException(http_resp=r)' | patch "${OUTPUT_DIR}/client/rest.py" + +# fix imports find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_asyncio.client./g' {} + find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client/from kubernetes_asyncio.client/g' {} + find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/getattr(client\.models/getattr(kubernetes_asyncio.client.models/g' {} + -#find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client\./from kubernetes.client./g' {} + -#find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/from client import /from kubernetes.client import /g' {} + - - - echo "---Done." From 7d9bc06e8e14500ad50ac2b372052ec6b46189a1 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Sat, 26 May 2018 23:38:23 +0200 Subject: [PATCH 3/4] fix: patch rest client to support strategic-merge-patch+json --- openapi/python-asyncio.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openapi/python-asyncio.sh b/openapi/python-asyncio.sh index 50bbdb0..12dad7c 100755 --- a/openapi/python-asyncio.sh +++ b/openapi/python-asyncio.sh @@ -60,6 +60,7 @@ find "${OUTPUT_DIR}/client" -type f -name \*.py ! -name '__init__.py' -exec sed # workaround https://github.com/swagger-api/swagger-codegen/pull/8204 # + closing session +# + support application/strategic-merge-patch+json echo '21a22,23 > import asyncio > @@ -67,19 +68,23 @@ echo '21a22,23 > def __del__(self): > asyncio.ensure_future(self.pool_manager.close()) > -164c169,171 +130a136,138 +> if headers['Content-Type'] == 'application/json-patch+json': +> if not isinstance(body, list): +> headers['Content-Type'] = 'application/strategic-merge-patch+json' +164c172,174 < async with self.pool_manager.request(**args) as r: --- > r = await self.pool_manager.request(**args) > if _preload_content: > -168,169c175,176 +168,169c178,179 < # log response body < logger.debug("response body: %s", r.data) --- > # log response body > logger.debug("response body: %s", r.data) -171,172c178,179 +171,172c181,182 < if not 200 <= r.status <= 299: < raise ApiException(http_resp=r) --- From 5c38dcdbd348b7e7a59e32802d89a3d4224cc632 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Thu, 14 Jun 2018 00:32:03 +0200 Subject: [PATCH 4/4] fix: docs, move patch to ext. file --- openapi/python-asyncio-rest.py.patch | 29 +++++++++++++++++++++++ openapi/python-asyncio.sh | 35 +++------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 openapi/python-asyncio-rest.py.patch diff --git a/openapi/python-asyncio-rest.py.patch b/openapi/python-asyncio-rest.py.patch new file mode 100644 index 0000000..0bc66e4 --- /dev/null +++ b/openapi/python-asyncio-rest.py.patch @@ -0,0 +1,29 @@ +21a22,23 +> import asyncio +> +81a84,86 +> def __del__(self): +> asyncio.ensure_future(self.pool_manager.close()) +> +130a136,138 +> if headers['Content-Type'] == 'application/json-patch+json': +> if not isinstance(body, list): +> headers['Content-Type'] = 'application/strategic-merge-patch+json' +164c172,174 +< async with self.pool_manager.request(**args) as r: +--- +> r = await self.pool_manager.request(**args) +> if _preload_content: +> +168,169c178,179 +< # log response body +< logger.debug("response body: %s", r.data) +--- +> # log response body +> logger.debug("response body: %s", r.data) +171,172c181,182 +< if not 200 <= r.status <= 299: +< raise ApiException(http_resp=r) +--- +> if not 200 <= r.status <= 299: +> raise ApiException(http_resp=r) diff --git a/openapi/python-asyncio.sh b/openapi/python-asyncio.sh index 12dad7c..7b098a9 100755 --- a/openapi/python-asyncio.sh +++ b/openapi/python-asyncio.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Copyright 2017 The Kubernetes Authors. +# Copyright 2018 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ ARGC=$# if [ $# -ne 2 ]; then echo "Usage:" - echo " python.sh OUTPUT_DIR SETTING_FILE_PATH" + echo " python-asyncio.sh OUTPUT_DIR SETTING_FILE_PATH" echo " Setting file should define KUBERNETES_BRANCH, CLIENT_VERSION, and PACKAGE_NAME" exit 1 fi @@ -44,7 +44,6 @@ popd > /dev/null source "${SCRIPT_ROOT}/client-generator.sh" source "${SETTING_FILE}" -# SWAGGER_CODEGEN_COMMIT=d2b91073e1fc499fea67141ff4c17740d25f8e83; \ SWAGGER_CODEGEN_COMMIT=f9b2839a3076f26db1b8fc61655a26662f2552ee; \ CLIENT_LANGUAGE=python-asyncio; \ CLEANUP_DIRS=(client/apis client/models docs test); \ @@ -61,35 +60,7 @@ find "${OUTPUT_DIR}/client" -type f -name \*.py ! -name '__init__.py' -exec sed # workaround https://github.com/swagger-api/swagger-codegen/pull/8204 # + closing session # + support application/strategic-merge-patch+json -echo '21a22,23 -> import asyncio -> -81a84,86 -> def __del__(self): -> asyncio.ensure_future(self.pool_manager.close()) -> -130a136,138 -> if headers['Content-Type'] == 'application/json-patch+json': -> if not isinstance(body, list): -> headers['Content-Type'] = 'application/strategic-merge-patch+json' -164c172,174 -< async with self.pool_manager.request(**args) as r: ---- -> r = await self.pool_manager.request(**args) -> if _preload_content: -> -168,169c178,179 -< # log response body -< logger.debug("response body: %s", r.data) ---- -> # log response body -> logger.debug("response body: %s", r.data) -171,172c181,182 -< if not 200 <= r.status <= 299: -< raise ApiException(http_resp=r) ---- -> if not 200 <= r.status <= 299: -> raise ApiException(http_resp=r)' | patch "${OUTPUT_DIR}/client/rest.py" +patch "${OUTPUT_DIR}/client/rest.py" "${SCRIPT_ROOT}/python-asyncio-rest.py.patch" # fix imports find "${OUTPUT_DIR}/client/" -type f -name \*.py -exec sed -i 's/import client\./import kubernetes_asyncio.client./g' {} +