#WithDirectory Exclude/Include doesn't not work as expected

1 messages · Page 1 of 1 (latest)

toxic estuary
#

I'm currently working on pre-call filtering on module call (https://github.com/dagger/dagger/issues/9490) and I noticied that my tests on Python was failing.
I made a repro and found out that Include and Exclude on WithDirectory are not working the same way as the ignore pattern.

Example:

//+ignore=["**", "!main.go"] <- ignore everything except main.go

But if I do convert that to a withDirectory, it's just ignoring everything

func (t *Test) TestDir() *dagger.Directory {
    dir := dag.Directory().WithNewFile("go.sum", "foo").WithNewFile("main.go", "bar")

    return dag.Directory().WithDirectory("/", dir, dagger.DirectoryWithDirectoryOpts{
        Include: []string{"main.go"},
        Exclude: []string{"**"},
    })
}

This will return an empty directory.
If I only set Include, then it's going to only pick up main.go.

That means that to support preload I need to check if the list contains !, if it does, only include them.
But that's wrong because you might ignore a subdirectory but include a specific file and still want the rest.

Like ["subdir/**", "!subdir/foo.txt"] -> which can be translated to include everything except subdir excluding subdir/foo.txt that should be included

So I'm a bit stuck, how should I handle that resolution?

GitHub

What are you trying to do? I believe Pre-call filtering should apply when calling modules/functions from other modules. It appears to be a conscious decision to not support so filing as a feature r...

dry thistle
#

Bk applies all includes before excludes. So you're including main.go and then excluding everything. The equivalent of // +ignore is to only use Exclude.

toxic estuary
#

Hmm even more strange then, that what I was doing first but python was still failing with the error:

No pyproject.toml found in current directory or any parent directory

dry thistle
#

There could be something else that's not the right fit in your implementation.

toxic estuary
#

I did almost the exact same as the loadContext, I'll dig a bit to see

#

I'm so confused, I checked the python SDK, provided as input the python sdk dir and the filter successfully works, pyproject is there