#Interface issues

1 messages · Page 1 of 1 (latest)

open sinew
#

I have minor issue with interfaces..
I would like to have something like that:

In remote module have:

@interface
class Provisioner(typing.Protocol):
    @function
    async def prepare(self, cont: dagger.Container) -> dagger.Container: ...

Then some function that would take

@object_type
class Remoter:
 @function
    async def build_all(
            self,
            prov Provisioner 
    ) -> dagger.Directory:
    ...

And in the local part where I use it I would like to have implementation of the interface

@object_type
class Example:
    @function
    async def prepare(self, cont: dagger.Container) -> dagger.Container:
        return (cont
                .with_exec(["apk", "add", "--no-cache", "git", "openssh-client", "ca-certificates"]))

and call build_all with my example provisioner.. But seems its impossible? how to convert local Example class to Provisioner?

I would like it to work like that..
My local module (that would call remote one with interface).


@object_type
class Example:
    @function
    async def prepare(self, cont: dagger.Container) -> dagger.Container:
        return (cont
                .with_exec(["apk", "add", "--no-cache", "git", "openssh-client", "ca-certificates"]))

@object_type
class Caller:
    @function
    async def build_local(self, cont: dagger.Container) -> dagger.Container:
        provisioner = Example() // Cannot do as_remoter_provisioner on that local object, how to make that object "managed" so it would have all those generated magic methods..
        return await dag.remoter().build_all(provisioner.as_remoter_provisioner())
heady quarry
#

Have you tried that?

open sinew
#

Yup..
That assumes I have 3 modules..
Module where I have interface (I have that).
Module where I have implementation.
Module where Im using both modules 👆

But I want to have module where I have implementation and module where I will be using it as 1 module..

heady quarry
#

gotcha. You can achieve this by using self invocaions (https://github.com/dagger/dagger/pull/10584).

You can run dagger develop --with-self-calls and that should generate the proper types so in your example you can do dag.Example().AsRemoterProvisioner.

Let us know if that works

GitHub

GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.

open sinew
#

Thats cool..
But I dont think it works for python (I didnt found any generated code for my classes)..