-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[python sdk] add v1beta1 models (#1252)
* [python sdk] add v1beta1 models * upgrade version of python SDK to 0.0.3 * remove v1Alpha3 python sdk * add some python models manually: v1Time and V1UnstructuredUnstructured * bring back v1alpha3 * create separate python sdk for v1alpha3 and v1beta1 * move on * release pkg on pypi.org * remove dist files * refine
- Loading branch information
1 parent
051d1de
commit 1d18594
Showing
281 changed files
with
12,954 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2019 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. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SWAGGER_JAR_URL="http://search.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.6/swagger-codegen-cli-2.4.6.jar" | ||
SWAGGER_CODEGEN_JAR="hack/gen-python-sdk/swagger-codegen-cli.jar" | ||
SWAGGER_CODEGEN_CONF="hack/gen-python-sdk/swagger_config.json" | ||
SWAGGER_CODEGEN_FILE="pkg/apis/KATIB_VERSION/swagger.json" | ||
TMP_CODEGEN_PATH="sdk/tmp/KATIB_VERSION" | ||
SDK_OUTPUT_PATH="sdk/python" | ||
POST_GEN_PYTHON_HANDLER="hack/gen-python-sdk/post_gen.py" | ||
KATIB_VERSIONS=(v1alpha3 v1beta1) | ||
|
||
echo "Downloading the swagger-codegen JAR package ..." | ||
wget -O ${SWAGGER_CODEGEN_JAR} ${SWAGGER_JAR_URL} | ||
|
||
|
||
for VERSION in ${KATIB_VERSIONS[@]}; do | ||
echo "Generating Python SDK for Kubeflow Katib ${VERSION} ..." | ||
SWAGGER_FILE=${SWAGGER_CODEGEN_FILE/KATIB_VERSION/$VERSION} | ||
TMP_PATH=${TMP_CODEGEN_PATH/KATIB_VERSION/$VERSION} | ||
java -jar ${SWAGGER_CODEGEN_JAR} generate -i ${SWAGGER_FILE} -l python -o ${TMP_PATH} -c ${SWAGGER_CODEGEN_CONF} -v | ||
|
||
python ${POST_GEN_PYTHON_HANDLER} ${TMP_PATH} ${SDK_OUTPUT_PATH}/${VERSION} | ||
done | ||
|
||
rm ${SWAGGER_CODEGEN_JAR} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
import shutil | ||
import sys | ||
|
||
|
||
def _rewrite_helper(input_file, output_file, rewrite_rules): | ||
rules = rewrite_rules or [] | ||
lines = [] | ||
with open(input_file, 'r') as f: | ||
while True: | ||
line = f.readline() | ||
if not line: | ||
break | ||
for rule in rules: | ||
line = rule(line) | ||
lines.append(line) | ||
with open(output_file, 'w') as f: | ||
f.writelines(lines) | ||
|
||
|
||
def update_python_sdk(src, dest, versions=('v1alpha3', 'v1beta1')): | ||
# tiny transformers to refine generated codes | ||
rewrite_rules = [ | ||
lambda l: l.replace('import katib', 'import kubeflow.katib'), | ||
lambda l: l.replace('from katib', 'from kubeflow.katib'), | ||
] | ||
|
||
src_dirs = [ | ||
os.path.join(src, 'katib'), | ||
os.path.join(src, 'katib', 'models'), | ||
os.path.join(src, 'test'), | ||
os.path.join(src, 'docs') | ||
] | ||
dest_dirs = [ | ||
os.path.join(dest, 'kubeflow', 'katib'), | ||
os.path.join(dest, 'kubeflow', 'katib', 'models'), | ||
os.path.join(dest, 'test'), | ||
os.path.join(dest, 'docs') | ||
] | ||
|
||
for src_dir, dest_dir in zip(src_dirs, dest_dirs): | ||
# remove previous generated files explicitly, in case of deprecated instances | ||
for file in os.listdir(dest_dir): | ||
path = os.path.join(dest_dir, file) | ||
if not os.path.isfile(path): | ||
continue | ||
for v in versions: | ||
if v in file.lower(): | ||
os.remove(path) | ||
break | ||
# fill latest generated files | ||
for file in os.listdir(src_dir): | ||
in_file = os.path.join(src_dir, file) | ||
out_file = os.path.join(dest_dir, file) | ||
if not os.path.isfile(in_file): | ||
continue | ||
_rewrite_helper(in_file, out_file, rewrite_rules) | ||
|
||
# update doc for API Endpoints and Models README.md | ||
buffer = [] | ||
update_buffer = [] | ||
with open(os.path.join(src, 'README.md'), 'r') as src_f: | ||
anchor = 0 | ||
for line in src_f.readlines(): | ||
if line.startswith('## Documentation For Models'): | ||
if anchor == 0: | ||
anchor = 1 | ||
elif line.startswith('##') and anchor == 1: | ||
anchor = 2 | ||
if anchor == 0: | ||
continue | ||
if anchor == 2: | ||
break | ||
update_buffer.append(line) | ||
with open(os.path.join(dest, 'README.md'), 'r') as dest_f: | ||
anchor = 0 | ||
for line in dest_f.readlines(): | ||
if line.startswith('## Documentation For Models'): | ||
if anchor == 0: | ||
buffer.extend(update_buffer) | ||
anchor = 1 | ||
elif line.startswith('##') and anchor == 1: | ||
anchor = 2 | ||
if anchor == 1: | ||
continue | ||
buffer.append(line) | ||
with open(os.path.join(dest, 'README.md'), 'w') as dest_f: | ||
dest_f.writelines(buffer) | ||
|
||
# clear working dictionary | ||
shutil.rmtree(src) | ||
|
||
|
||
if __name__ == '__main__': | ||
update_python_sdk(src=sys.argv[1], dest=sys.argv[2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"packageName" : "katib", | ||
"projectName" : "katib", | ||
"packageVersion": "0.1", | ||
"importMappings": { | ||
"V1Container": "from kubernetes.client import V1Container", | ||
"V1ListMeta": "from kubernetes.client import V1ListMeta", | ||
"V1ObjectMeta": "from kubernetes.client import V1ObjectMeta", | ||
"V1HTTPGetAction": "from kubernetes.client import V1HTTPGetAction" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# V1Time | ||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# V1UnstructuredUnstructured | ||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ | |
] | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
"output_type": "execute_result" | ||
}, | ||
{ | ||
"data": { | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.