Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script to create kubernetes_asyncio python client #60

Merged
merged 4 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions openapi/python-asyncio-rest.py.patch
Original file line number Diff line number Diff line change
@@ -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)
70 changes: 70 additions & 0 deletions openapi/python-asyncio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# 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.
# 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-asyncio.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=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' {} \;

# workaround https://github.com/swagger-api/swagger-codegen/pull/8204
# + closing session
# + support application/strategic-merge-patch+json
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' {} +
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' {} +

echo "---Done."
55 changes: 55 additions & 0 deletions openapi/python-asyncio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.kubernetes</groupId>
<artifactId>client-python</artifactId>
<version>1.0-SNAPSHOT</version>
<name>client-python</name>
<url>http://kubernetes.io</url>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger-codegen-version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${generator.spec.path}</inputSpec>
<language>python</language>
<library>asyncio</library>
<gitUserId>kubernetes-client</gitUserId>
<gitRepoId>python</gitRepoId>
<configOptions>
<packageName>${generator.package.name}</packageName>
<packageVersion>${generator.client.version}</packageVersion>
<sortParamsByRequiredFlag>true</sortParamsByRequiredFlag>
</configOptions>
<output>${generator.output.path}</output>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- dependencies are needed for the client being generated -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger-annotations-version}</version>
</dependency>
</dependencies>
<properties>
<swagger-annotations-version>1.5.0</swagger-annotations-version>
<maven-plugin-version>1.0.0</maven-plugin-version>

<!-- Default values for the generator parameters. -->
<generator.output.path>.</generator.output.path>
<generator.spec.path>swagger.json</generator.spec.path>
<generator.package.name>swagger_client</generator.package.name>
<generator.client.version>unversioned</generator.client.version>
</properties>
</project>