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 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
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:

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Pipfile
.vscode/
.idea/
.node-version
Expand Down
7 changes: 5 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 client/dist/* -u __token__ -p ${PYPI_API_TOKEN}

generate:
rm -Rf $(WD)
Expand All @@ -39,4 +42,4 @@ 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)
74 changes: 37 additions & 37 deletions sdks/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,67 @@ 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.models.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))
pprint(api_response)

```

Note that `_check_type=False` is required here to avoid type checks against `manifest` which is a Python dictionary.

Alternative, you can submit a workflow with an instance of `IoArgoprojWorkflowV1alpha1Workflow` constructed via the SDK like the following:
Alternative, you can submit a workflow with an instance of `IoArgoprojWorkflowV1alpha1Workflow` constructed via the SDK
like the following:

```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
4 changes: 2 additions & 2 deletions sdks/python/examples/hello-world-from-object.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
image='docker/whalesay:latest', command=['cowsay'], args=['hello world']))]))

api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_instance = workflow_service_api.WorkflowServiceApi(api_client=api_client)
api_response = api_instance.create_workflow(
namespace='default',
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest))
pprint(api_response)
13 changes: 6 additions & 7 deletions sdks/python/examples/hello-world-from-raw-yaml.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pprint import pprint

import requests
import yaml

import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import IoArgoprojWorkflowV1alpha1WorkflowCreateRequest
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
IoArgoprojWorkflowV1alpha1WorkflowCreateRequest
import requests
import yaml

configuration = argo_workflows.Configuration(host="https://127.0.0.1:2746")
configuration.verify_ssl = False
Expand All @@ -16,7 +16,6 @@
api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
api_response = api_instance.create_workflow(
namespace='default',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
workflow=manifest, _check_type=False))
namespace='argo',
body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest))
pprint(api_response)