#Invoke reusable module function from python code started with CLI dagger run not dagger call

1 messages · Page 1 of 1 (latest)

thorn patrol
#

I am trying to invoke a reusable module function from Python but I do not know how to approach it.
I created a public gitlab repo, and I can invoke the dagger CLI "dagger functions -m dagger-shared-module-functions" and "dagger call -m dagger-shared-module-functions my-function"
The dagger .json is setup for this, but I want to invoke these functions not using the CLI but from my python code when executing the "dagger run python3 main.py"

What am I doing wrong or what is missing to invoke for example the "my_function" on the module, the objects() and interfaces() are always return empty []

#

In the main.py I have this code snippet

        # Define the Git repository and the commit hash
        git_repo_url = "gitlab.com/brightlight-techhub/dagger/dagger-shared-module-functions"
        commit_hash = "9808d910504e3dd0c402a0c7f56724ae28eee8df"

        git_module_source = self.client.module_source(f"{git_repo_url}@{commit_hash}")
        print("Loaded module source:", dir(git_module_source))

        module_x = git_module_source.as_module()
        print(f"module_x: {type(module_x)}", dir(module_x))

        # Get the module ID correctly
        module_id = await module_x.id()  # Await this method to get the actual ID
        print(f"Module ID: {type(module_id)}", module_id)

        # Use the ID to load the module
        loaded_module = self.client.load_module_from_id(module_id)
        print("Loaded Module:", dir(loaded_module))

        objects = await loaded_module.objects()
        print("Available Objects:", objects)

        interfaces = await loaded_module.interfaces()
        print("Available Interfaces:", interfaces)
        for obj in objects:
            print("Object:", obj)
            # List available methods for each object
            methods = obj.methods()
            print("Available Methods:", methods)

            for method in methods:
                print("Method:", dir(method))
                # Call the method and print the result
                result = await method.call()
                print(f"Method {method.name} result: {result}")
#

Invoke reusable module function from python code started with CLI dagger run not dagger call

frail flume
thorn patrol
#

I hope this then also works with not only public git repos but also private gitlab and github repos

frail flume
#

Yep 🙂