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

feat: Python SDK publish #7363

Merged
merged 21 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions .github/workflows/sdks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
- run: make --directory sdks/${{matrix.name}} publish -B
env:
JAVA_SDK_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have this yet but I can add before next release. Could you use your fork and https://test.pypi.org/ to test that the entire release process works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrytangyuan I tested the release process and discovered two bugs:

  • secret reference was missing ${}
  • the built full dist path was missing

I fixed those. During testing I had to name the package argo-workflows-test because I do not have permission to argo-workflows. Here are the results:

10 changes: 8 additions & 2 deletions sdks/python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ DOCKER = docker run --rm -v $(WD):/wd --workdir /wd
CHOWN = chown -R $(shell id -u):$(shell id -g)

publish: generate
echo "TODO: Publish the package to PyPI"
pip install setuptools twine build
python -m build --sdist --wheel --outdir client/dist/ client
twine check client/dist/*
twine upload dist/* -u __token__ -p $PYPI_API_TOKEN

generate:
rm -Rf $(WD)
Expand All @@ -39,4 +42,7 @@ generate:
--global-property packageName=argo_workflows \
--generate-alias-as-model
# https://vsupalov.com/docker-shared-permissions/#set-the-docker-user-when-running-your-container
$(CHOWN) $(WD) || sudo $(CHOWN) $(WD)
$(CHOWN) $(WD) || sudo $(CHOWN) $(WD)
# run the SDK fix for the ApiClient
$(CHOWN) ./sdk_fix.py
@./sdk_fix.py
72 changes: 36 additions & 36 deletions sdks/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ from pprint import pprint
import requests
import yaml

import openapi_client
from openapi_client.api import workflow_service_api
from openapi_client.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
IoArgoprojWorkflowV1alpha1WorkflowCreateRequest

configuration = openapi_client.Configuration(host="https://127.0.0.1:2746")
configuration = argo_workflows.Configuration(host="https://127.0.0.1:2746")
configuration.verify_ssl = False

resp = requests.get('https://raw.githubusercontent.com/argoproj/argo-workflows/master/examples/hello-world.yaml')
manifest = yaml.safe_load(resp.text)
manifest['spec']['serviceAccountName'] = 'argo'

api_client = openapi_client.ApiClient(configuration)
api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.workflow_service_create_workflow(
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
workflow=manifest, _check_type=False))
api_response = api_instance.create_workflow(
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
workflow=manifest, _check_type=False))
pprint(api_response)

```

Note that `_check_type=False` is required here to avoid type checks against `manifest` which is a Python dictionary.
Expand All @@ -52,39 +52,39 @@ Alternative, you can submit a workflow with an instance of `IoArgoprojWorkflowV1
```python
from pprint import pprint

import openapi_client
from openapi_client.api import workflow_service_api
from openapi_client.model.container import Container
from openapi_client.model.io_argoproj_workflow_v1alpha1_template import \
IoArgoprojWorkflowV1alpha1Template
from openapi_client.model.io_argoproj_workflow_v1alpha1_workflow import (
IoArgoprojWorkflowV1alpha1Template, IoArgoprojWorkflowV1alpha1Workflow)
from openapi_client.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.container import Container
from argo_workflows.model.io_argoproj_workflow_v1alpha1_template import IoArgoprojWorkflowV1alpha1Template
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow import IoArgoprojWorkflowV1alpha1Workflow
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
IoArgoprojWorkflowV1alpha1WorkflowCreateRequest
from openapi_client.model.io_argoproj_workflow_v1alpha1_workflow_spec import \
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_spec import \
IoArgoprojWorkflowV1alpha1WorkflowSpec
from openapi_client.model.object_meta import ObjectMeta
from argo_workflows.model.object_meta import ObjectMeta

configuration = openapi_client.Configuration(host="https://127.0.0.1:2746")
configuration = argo_workflows.Configuration(host="https://127.0.0.1:2746")
configuration.verify_ssl = False

manifest = IoArgoprojWorkflowV1alpha1Workflow(
metadata=ObjectMeta(generate_name='hello-world-'),
spec=IoArgoprojWorkflowV1alpha1WorkflowSpec(
service_account_name='argo',
entrypoint='whalesay',
templates=[
IoArgoprojWorkflowV1alpha1Template(
name='whalesay',
container=Container(
image='docker/whalesay:latest', command=['cowsay'], args=['hello world']))]))

api_client = openapi_client.ApiClient(configuration)
metadata=ObjectMeta(generate_name='hello-world-'),
spec=IoArgoprojWorkflowV1alpha1WorkflowSpec(
entrypoint='whalesay',
templates=[
IoArgoprojWorkflowV1alpha1Template(
name='whalesay',
container=Container(
image='docker/whalesay:latest', command=['cowsay'], args=['hello world']))]))

api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.workflow_service_create_workflow(
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest))
pprint(api_response)

if __name__ == '__main__':
api_response = api_instance.create_workflow(
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest))
pprint(api_response)

```

## Examples
Expand Down
5 changes: 5 additions & 0 deletions sdks/python/client/argo_workflows/api_client.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdks/python/examples/hello-world-from-object.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.create_workflow(
namespace='default',
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest))
pprint(api_response)
2 changes: 1 addition & 1 deletion sdks/python/examples/hello-world-from-raw-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.create_workflow(
namespace='default',
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
workflow=manifest, _check_type=False))
pprint(api_response)
23 changes: 23 additions & 0 deletions sdks/python/sdk_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3
from pathlib import Path

api_client_path = str(Path(__file__).parent / 'client' / 'argo_workflows' / 'api_client.py')
api_client_lines = open(api_client_path, 'r').readlines()
line_to_insert_at = -1

for i, line in enumerate(api_client_lines):
if 'deserialized_data = validate_and_convert_types' in line:
line_to_insert_at = i

if line_to_insert_at == -1:
raise Exception('could not find line to insert SDK fix at')

fix = """
# TODO: fix this deserialization hack"
flaviuvadan marked this conversation as resolved.
Show resolved Hide resolved
from datetime import timezone
now = datetime.now(tz=timezone.utc)
received_data['status']['startedAt'], received_data['status']['finishedAt'] = now, now
"""
api_client_lines.insert(line_to_insert_at, fix)
with open(api_client_path, 'w') as f:
f.write(''.join(api_client_lines))