#Possible to use dagger.Directory with os.path or os.walk ?

1 messages · Page 1 of 1 (latest)

warped creek
#

I'm trying to build a pipeline that infers 'actions' from the repo content. And run dagger function depending on a detected plan. e.g. pre-commit if pre-commit-config.yaml is there.

Aim is to have a high level module 'pipeline' that 1st detect what needs to be run and run it based on the content. However, it's not clear to me in the doc how the standard python can be used with dagger.Directory.

cyan thicket
warped creek
#

I see. So if I wanted walk a dagger.Directory, I would have to rebuild that logic.

cyan thicket
#

But it's not API-compatible with the Python stdlib equivalent, if that's what you mean. If you specifically want an API-compatible implementation, then yes you need to implement that compat layer yourself.

warped creek
#

got it. let me play with Directory.glob() and see where I get. thanks for the quick reply!

cyan thicket
#

If you want to walk everything, pass "**" as pattern argument (to match every entry everywhere in the tree)

warped creek
#

yes. similarly, any third-party libraries using directly or indirectly path or pathlike objects are not usable with dagger modules/functions. eg. using the git.Repo, pydantic-settings .env. is that correct?

cyan thicket
#

They will all work, but they will interact with the filesystem of the container inside which your function is sandboxed. So probably not what you want

#

However, it's possible to export the contents of a directory from the engine into your runtime container. Then from there, use regular libraries to interact with the exported version. That should only be used for compatibily though, as there is a performance tax to exporting in this way (the entire contents of the directory or file is transfered out of the engine)

warped creek
#

interesting. I must have missed that in the docs. how do you export the directory into the runtime container?

cyan thicket
#

Directory.export(<path>)

warped creek
#

oh nice! I got confused by "Writes the contents of the directory to a path on the host." I thought host was refering to the actual running host rather than the runtime container. I will try that! thanks. this is so helpful.