#defaultpath / default arg value

1 messages · Page 1 of 1 (latest)

vale sand
#

Noob in dagger here. If I have a defaultpath already set like this

@function
    def build_container(
        self,
        source: SourceDir,
        libs: Annotated[
            Directory,
            Doc("Libs directory"),
            Ignore([".venv", ".ruff_cache", ".pytest_cache", ".pdm-build"]),
            DefaultPath("libs/aukafka"),
        ],
    ) -> Container:     

how I can stop requiring this arg in next functions like this one

@function
    def build_env(
        self,
        source: SourceDir
    ) -> Container:
        return (
            self.build_container(source)```
#

I am getting weird engine errors, like there is no ID for directory if I set default value for arg

vale sand
#

this

            Directory,
            Doc("Libs directory"),
            Ignore([".venv", ".ruff_cache", ".pytest_cache", ".pdm-build"]),
            DefaultPath("libs/aukafka"),
        ]
        | None``` 
gives me ! RayInference.build_container() missing 1 required positional argument: 'libs'
earnest needle
vale sand
#

so i need to copy paste annotation?

#

how to avoid this?

#

using call chain?

earnest needle
#

Are you expecting to call both build_env and build_container via the CLI?

vale sand
#

no, probably only build_env

#

but I have build_env_ci 🙂 so again copy paste

#

build_container is like a base function (base container)

earnest needle
#

Ok, so you can move the annotation to the build_env function only

#

Seems like the build_container doesn't need the defaultPath then

vale sand
#

and remove @function decorator from it?

#

keep it pure?

earnest needle
#

If you're not expecting users to call it directly

vale sand
#

so, something like this def build_container(self, source: Directory, libs: Directory) -> Container:

vale sand
#

but I would have build_env, build_env_ci etc

#

going to repeat that source and libs

earnest needle
#

And set them at the class level

#

Si you don't repeat them for every function

#

That's in the docs

vale sand
#

oh! I see

#

another what I thought is call chain

#

like create libs() function that takes lib Directory, it will filter out later on in build_env

#

so the problem that I am facing -> I have build_env (monorepo) and some local dependencies that I need to detect and copy from project.toml

earnest needle
vale sand
#

so, the idea is dynamically read project.toml and filter out libs (don't mount them into final image)

#

I am pretty sure it's doable, just trying to understand the sugar

earnest needle