Skip to content

Commit

Permalink
SDK - Client - Added API models to the generated API
Browse files Browse the repository at this point in the history
The API objects should now be available in the generated client API: `kfp.Client().jobs.models.ApiJob`.
  • Loading branch information
Ark-kun committed Oct 16, 2019
1 parent fd6c756 commit 59fa34c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ def camel_case_to_snake_case(name):
import re
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower()

for api_name in dir(api_module):
if not api_name.endswith('ServiceApi'):
for api_name in dir(api_module.api):
if not api_name.endswith('ServiceApi'): # E.g. kfp_server_api.api.RunServiceApi
continue

short_api_name = camel_case_to_snake_case(api_name[0:-len('ServiceApi')]) + 's'
api_name = api_name[0:-len('ServiceApi')] # E.g. Job, Run or PipelineUpload
short_api_name = camel_case_to_snake_case(api_name) + 's'
api_struct = Struct()
setattr(target_struct, short_api_name, api_struct)
service_api = getattr(api_module, api_name)
service_api = getattr(api_module.api, api_name)
initialized_service_api = service_api(api_client)
for member_name in dir(initialized_service_api):
if member_name.startswith('_') or member_name.endswith('_with_http_info'):
Expand All @@ -61,6 +62,8 @@ def camel_case_to_snake_case(name):
bound_member = getattr(initialized_service_api, member_name)
setattr(api_struct, member_name, bound_member)

api_struct.models = getattr(api_module.models, 'api_' + api_name.lower()) # E.g. kfp_server_api.models.api_job which contains ApiJob, ApiPipelineSpec etc


KF_PIPELINES_ENDPOINT_ENV = 'KF_PIPELINES_ENDPOINT'
KF_PIPELINES_UI_ENDPOINT_ENV = 'KF_PIPELINES_UI_ENDPOINT'
Expand Down Expand Up @@ -92,7 +95,7 @@ def __init__(self, host=None, client_id=None, namespace='kubeflow'):
self._uihost = os.environ.get(KF_PIPELINES_UI_ENDPOINT_ENV, host)
config = self._load_config(host, client_id, namespace)
api_client = kfp_server_api.api_client.ApiClient(config)
_add_generated_apis(self, kfp_server_api.api, api_client)
_add_generated_apis(self, kfp_server_api, api_client)
self._run_api = kfp_server_api.api.run_service_api.RunServiceApi(api_client)
self._experiment_api = kfp_server_api.api.experiment_service_api.ExperimentServiceApi(api_client)
self._pipelines_api = kfp_server_api.api.pipeline_service_api.PipelineServiceApi(api_client)
Expand Down

0 comments on commit 59fa34c

Please sign in to comment.