#Python: static directory vs set as arg

1 messages · Page 1 of 1 (latest)

elder tusk
#

I can't figure out what I'm doing wrong here nor can I find an exact doc that makes it make sense.

This works.

    @function
    async def build(self, source: dagger.Directory) -> dagger.Container:
        container = (
            dag.container(platform=dagger.Platform("linux/amd64"))
                .from_("python:3.11")
                .with_workdir("/service")
                .with_directory(".", source)
        )
        return await (
            container
        )

but this doesn't

    @function
    async def build(self) -> dagger.Container:
        source = dagger.Directory(".")
        container = (
            dag.container(platform=dagger.Platform("linux/amd64"))
                .from_("python:3.11")
                .with_workdir("/service")
                .with_directory(".", source)
        )
        return await (
            container
        )
hearty zealot
elder tusk
#

shoot so is there any way to hard code directories like that in the function?

hearty zealot
#

Not right now, but there is work to make the interface cleaner.

can you tell me more about what you are trying to do and why passing a direcftory in is not an option for you?

elder tusk
#

I guess it's coming from a place where I don't think I need to expect developers to pass --source . for every command

#

(I'm really new to dagger. been following it since the early GA release and this new nonCUE way seems like the digestable way for our developers). We have a monorepo of python, golang, and typescript services

hearty zealot
elder tusk
#

ah ill check that out

#

what about instantiating a cachevolume?

        pip_cache = dag.CacheVolume("pip-cache")

?

                .with_mounted_cache("/root/.cache/pip", pip_cache)
hearty zealot
#

This should work, its different since the volume does not refer to your host but is managed by the dagger engine already.

Are you seeing issues?

Should be dag.cache_volume though