CermakM / argo-python-dsl

Python DSL for Argo Workflows | Mirrored to https://github.com/argoproj-labs/argo-python-dsl
https://github.com/argoproj/argo
Apache License 2.0
55 stars 6 forks source link

cannot import name 'models' from 'argo.workflows' #7

Closed brtasavpatel closed 4 years ago

brtasavpatel commented 4 years ago

Describe the bug I am on master branch and tried following simple HelloWorld example. when I try to from argo.workflows.dsl import Workflow I get

In [2]: from argo.workflows.dsl import Workflow
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-11eebaacd24f> in <module>
----> 1 from argo.workflows.dsl import Workflow

~/Workspace/argo-python-dsl/argo/workflows/dsl/__init__.py in <module>
     15
     16 # modules
---> 17 from . import tasks
     18 from . import templates
     19

~/Workspace/argo-python-dsl/argo/workflows/dsl/tasks.py in <module>
     23 )
     24
---> 25 from ._arguments import artifact
     26 from ._arguments import parameter
     27 from ._base import Prop

~/Workspace/argo-python-dsl/argo/workflows/dsl/_arguments.py in <module>
      9 )
     10
---> 11 from ._base import Prop
     12
     13 __all__ = ["artifact", "parameter", "V1alpha1Artifact", "V1alpha1Parameter"]

~/Workspace/argo-python-dsl/argo/workflows/dsl/_base.py in <module>
     14 from typing import Union
     15
---> 16 from argo.workflows import models
     17
     18 T = TypeVar("T")

ImportError: cannot import name 'models' from 'argo.workflows' (./argo/workflows/__init__.py)

Python Version : Python 3.7.5

Installed argo-workflows using pip install -e "git+git://github.com/CermakM/argo-client-python@argo/v2.5.0#egg=argo-workflows"

To Reproduce Steps to reproduce the behavior:

  1. Go to 'https://github.com/CermakM/argo-python-dsl#getting-started and follow the instruction on master branch code.

Screenshots image

pip list | grep -i argo
argo-models              2.2.1a0
argo-workflows           3.0.0rc0
yxue-kabam commented 4 years ago

Hi, can you uninstall argo-models and install argo-client-python ? pip install -U git+git://github.com/CermakM/argo-client-python.git

What I have is different than yours:

argo-workflows     3.0.0rc0
argo-workflows-dsl 0.1.0.dev0

I am not sure what is argo-models project though.

here is the code successfully submit the hello-world example for me.

from argo.workflows.client import V1alpha1Api

from argo.workflows.config import load_kube_config

from argo.workflows.dsl import Workflow
from argo.workflows.dsl import template

from argo.workflows.dsl.templates import V1Container
from argo.workflows.config import load_kube_config

load_kube_config()

api = V1alpha1Api()

class HelloWorld(Workflow):

    entrypoint = "whalesay"

    @template
    def whalesay(self) -> V1Container:
        container = V1Container(
            image="docker/whalesay:latest",
            name="whalesay",
            command=["cowsay"],
            args=["hello world"]
        )

        return container

wf = HelloWorld()
print(wf)
result = api.create_namespaced_workflow('argo', wf)
print(result.metadata.name)
brtasavpatel commented 4 years ago

how did you install argo-workflows-dsl though? I cloned master branch and did python setup.py install is that the correct way to install?

yxue-kabam commented 4 years ago

I cannot speak for the author whether this is the correct way, seeing both libraries is under active development (especially this one), I'd expect a better installation process in the future.

What I did to get it working: (should not be a reliable way)

start a new virtual env,

pip install -U git+git://github.com/CermakM/argo-client-python.git
pip install -U git+git://github.com/CermakM/argo-python-dsl.git
CermakM commented 4 years ago

@yxue-kabam That is exactly right and thanks for the active participation.

The client library has already been released to PyPI: https://pypi.org/project/argo-workflows/, so it can be installed directly as pip install -U argo-workflows.

The DSL, however, is indeed under active development and it is currently 'safer' to install it from github directly.

@brtasavpatel does the problem with the import persist? As far as the other issue is concerned, I commented right there :)

PS: argo-models are not my doing and are not related to this library

brtasavpatel commented 4 years ago

thanks @yxue-kabam and @CermakM for the replies, I think because of that argo-models package I had some module name conflicts that's why it wasn't working,

code snippet above works, though there's one issue with that (I don't know if it's intentional) when I try to submit same workflow twice I get

ApiException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Wed, 26 Feb 2020 22:32:48 GMT', 'Content-Length': '286'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"The POST operation against Workflow.argoproj.io could not be completed at this time, please try again.","reason":"ServerTimeout","details":{"name":"POST","group":"argoproj.io","kind":"Workflow"},"code":500}

Here this exception is totally misleading. I have investigated and found out that it's failing because argo doesn't allow same names for the workflows. if I set workflow name to empty string like this : wf.name = '' I can submit the workflow multiple times.

I wanted to know Is this an intended behavior?

brtasavpatel commented 4 years ago

sorry guys to bombard you all with questions, I have one more question. how can I specify which Service Account to use when I submit a workflow? for eg with argo cli I can do

argo submit --serviceaccount my-serviceaccount --watch https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml

how can I specify service account? either in dsl or create_namespaced_workflow?

brtasavpatel commented 4 years ago

sorry guys to bombard you all with questions, I have one more question. how can I specify which Service Account to use when I submit a workflow? for eg with argo cli I can do

argo submit --serviceaccount my-serviceaccount --watch https://raw.githubusercontent.com/argoproj/argo/master/examples/hello-world.yaml

how can I specify service account? either in dsl or create_namespaced_workflow?

if anyone else is wondering about this one. I got it to work using @CermakM 's help.

here's how you can do that, specify service_account_name in Workflow class.

class HelloWorld(Workflow):
    entrypoint = "whalesay"
    service_account_name = "argo-workflow"

    @template
    def whalesay(self):
        container = V1Container(
            image="docker/whalesay:latest",
            name="whalesay",
            command=["cowsay"],
            args=["hello world"]
        )
        return container
brtasavpatel commented 4 years ago

again thanks a lot @CermakM for great work. :-)