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

[python sdk] add v1beta1 models #1252

Merged
merged 10 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
43 changes: 43 additions & 0 deletions hack/gen-python-sdk/gen_sdk.sh
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}
56 changes: 56 additions & 0 deletions hack/gen-python-sdk/post_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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', 'from kubeflow import katib'),
lambda l: l.replace('from katib', 'from kubeflow.katib'),
]

src_dirs = [
os.path.join(src, 'katib', 'models'),
os.path.join(src, 'test'),
os.path.join(src, 'docs')
]
dest_dirs = [
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):
for v in versions:
if v in file.lower():
os.remove(os.path.join(dest_dir, file))
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)
_rewrite_helper(in_file, out_file, rewrite_rules)
# clear working dictionary
shutil.rmtree(src)


if __name__ == '__main__':
update_python_sdk(src=sys.argv[1], dest=sys.argv[2])
Binary file added hack/gen-python-sdk/swagger-codegen-cli.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions hack/gen-python-sdk/swagger_config.json
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"
}
}
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions sdk/python/v1alpha3/docs/V1Time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# V1Time
andreyvelich marked this conversation as resolved.
Show resolved Hide resolved

## 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)
7 changes: 7 additions & 0 deletions sdk/python/v1alpha3/docs/V1UnstructuredUnstructured.md
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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**algorithm_name** | **str** | | [optional]
**algorithm_settings** | [**list[V1alpha3AlgorithmSetting]**](V1alpha3AlgorithmSetting.md) | Key-value pairs representing settings for suggestion algorithms. |
**algorithm_settings** | [**list[V1alpha3AlgorithmSetting]**](V1alpha3AlgorithmSetting.md) | Key-value pairs representing settings for suggestion algorithms. | [optional]
**early_stopping** | [**V1alpha3EarlyStoppingSpec**](V1alpha3EarlyStoppingSpec.md) | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Name | Type | Description | Notes
**objective** | [**V1alpha3ObjectiveSpec**](V1alpha3ObjectiveSpec.md) | Describes the objective of the experiment. | [optional]
**parallel_trial_count** | **int** | How many trials can be processed in parallel. Defaults to 3 | [optional]
**parameters** | [**list[V1alpha3ParameterSpec]**](V1alpha3ParameterSpec.md) | List of hyperparameter configurations. | [optional]
**resume_policy** | **str** | Describes resuming policy which usually take effect after experiment terminated. | [optional]
**trial_template** | [**V1alpha3TrialTemplate**](V1alpha3TrialTemplate.md) | Template for each run of the trial. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
]
},
"metadata": {},
"output_type": "display_data"
"output_type": "execute_result"
},
{
"data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

# flake8: noqa
"""
katib
Katib

swagger description for katib # noqa: E501

OpenAPI spec version: v0.1
Swagger description for Katib # noqa: E501

OpenAPI spec version: v1alpha3-0.1

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

Expand Down Expand Up @@ -53,12 +53,3 @@
from kubeflow.katib.models.v1alpha3_trial_spec import V1alpha3TrialSpec
from kubeflow.katib.models.v1alpha3_trial_status import V1alpha3TrialStatus
from kubeflow.katib.models.v1alpha3_trial_template import V1alpha3TrialTemplate









86 changes: 86 additions & 0 deletions sdk/python/v1alpha3/kubeflow/katib/models/v1_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# coding: utf-8

"""
Katib

Swagger description for Katib # noqa: E501

OpenAPI spec version: v1beta1-0.1

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


import pprint
import re # noqa: F401

import six


class V1Time(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""

"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
swagger_types = {
}

attribute_map = {
}

def __init__(self): # noqa: E501
"""V1Time - a model defined in Swagger""" # noqa: E501
self.discriminator = None

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in six.iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
if issubclass(V1Time, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, V1Time):
return False

return self.__dict__ == other.__dict__

def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# coding: utf-8

"""
Katib

Swagger description for Katib # noqa: E501

OpenAPI spec version: v1beta1-0.1

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


import pprint
import re # noqa: F401

import six


class V1UnstructuredUnstructured(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""

"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
swagger_types = {
}

attribute_map = {
}

def __init__(self): # noqa: E501
"""V1UnstructuredUnstructured - a model defined in Swagger""" # noqa: E501
self.discriminator = None

def to_dict(self):
"""Returns the model properties as a dict"""
result = {}

for attr, _ in six.iteritems(self.swagger_types):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
if issubclass(V1UnstructuredUnstructured, dict):
for key, value in self.items():
result[key] = value

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, V1UnstructuredUnstructured):
return False

return self.__dict__ == other.__dict__

def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8

"""
katib
Katib

swagger description for katib # noqa: E501
Swagger description for Katib # noqa: E501

OpenAPI spec version: v0.1
OpenAPI spec version: v1alpha3-0.1

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8

"""
katib
Katib

swagger description for katib # noqa: E501
Swagger description for Katib # noqa: E501

OpenAPI spec version: v0.1
OpenAPI spec version: v1alpha3-0.1

Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
Expand All @@ -16,6 +16,9 @@

import six

from kubeflow.katib.models.v1alpha3_algorithm_setting import V1alpha3AlgorithmSetting # noqa: F401,E501
from kubeflow.katib.models.v1alpha3_early_stopping_spec import V1alpha3EarlyStoppingSpec # noqa: F401,E501


class V1alpha3AlgorithmSpec(object):
"""NOTE: This class is auto generated by the swagger code generator program.
Expand Down
Loading