Skip to content

feat: apply ignore metadata on directory flags from the CLI - #8436

Merged
TomChv merged 16 commits into
dagger:mainfrom
TomChv:feat/apply-ignore-on-any-dir-source
Sep 24, 2024
Merged

TomChv merged 16 commits into
dagger:mainfrom
TomChv:feat/apply-ignore-on-any-dir-source

Conversation

@TomChv

@TomChv TomChv commented Sep 12, 2024 •

Copy link
Copy Markdown
Member

Closes #7832

Update ModuleFunction.setCallInputs to apply ignore patterns on Directory that have ignore as metadatas.
Update ResolveDirectoryFromCaller arguments to supports optional ignore argument.
Update CLI Directory handling to also apply ignore on Directory if ignore is set.

Still need to add tests, I only manually tested now: Test added

Example with Typescript:

import { Directory, object, func, argument } from "@dagger.io/dagger"

@object()
class Test {
  @func()
  ignoreDir(
    @argument({ ignore: ["**", "!src/"]})
    dir: Directory
  ): Directory {
    return dir
  }
}
$ dagger call ignore-dir --dir .

_type: Directory
digest: sha256:c19b982b8d2eaab4a9fae8b20da1e906b77f8d3579a6506ea2f597afc0a17f30
entries:
    - src

@TomChv
TomChv requested review from a team as code owners September 12, 2024 18:06
@TomChv TomChv self-assigned this Sep 12, 2024
@TomChv

TomChv commented Sep 12, 2024

Copy link
Copy Markdown
Member Author

I still need to write tests for them, will do tomorrow!

@TomChv
TomChv force-pushed the feat/apply-ignore-on-any-dir-source branch from d222af3 to 6d78676 Compare September 13, 2024 09:28
@TomChv

TomChv commented Sep 13, 2024

Copy link
Copy Markdown
Member Author

Test added, however the CI look super bad, I'm trying to make it green

@TomChv
TomChv force-pushed the feat/apply-ignore-on-any-dir-source branch 2 times, most recently from d021cb0 to e8e4346 Compare September 16, 2024 09:33
@TomChv
TomChv requested a review from a team as a code owner September 16, 2024 11:44
@TomChv

TomChv commented Sep 16, 2024

Copy link
Copy Markdown
Member Author

After fixing my issue with type handling, I'm seeing such a weird error on that PR:

All the sdk check steps are failing for the same reason:

error: No `pyproject.toml` found in current directory or any parent directory

-> check --targets=sdk/elixir: https://dagger.cloud/dagger/traces/80fbfe075e520d2284f01154b0787ce9
-> check --targets=sdk/typescript: https://dagger.cloud/dagger/traces/cab80ff071727e3005615ddf2bbe86b9
-> check --targets=sdk/python: https://dagger.cloud/dagger/traces/4907620f08913488f055d319944446af

And basically all the SDK check related job.

@helderco do you have any idea why I would get such error?

I also can see all the tests python failing in TestModules: https://dagger.cloud/dagger/traces/8cfb5ad4249ebe191b9f84010cc73fd3

@helderco

Copy link
Copy Markdown
Contributor

I don't think it's sdk check particularly. Should happen on just dagger functions. It's because /.dagger depends on /sdk/python/dev and there must be an issue loading that module's files.

Comment thread core/modfunc.go Outdated
Comment on lines +140 to +145
if len(arg.metadata.Ignore) > 0 {
converted, err = fn.applyIgnoreOnDir(ctx, opts.Server, arg.metadata, converted)
if err != nil {
return nil, fmt.Errorf("failed to apply ignore pattern on arg %q: %w", input.Name, err)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a directory provided via CLI, and uploaded via bk.LocalImport, this will filter the resulting directory another time, but with this, right?

{
    directory { 
        withDirectory(path: "/", directory: "<ID>", exclude: ["<same ignore pattterns>"]) 
    }
}

I'd rather find a fix so it doesn't filter twice, before enabling this for all directories. Simply having support for the CLI is enough to deprecate views.

This is what's causing the issue with sdk/python/dev by the way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a directory provided via CLI, and uploaded via bk.LocalImport, this will filter the resulting directory another time, but with this, right?

You're right, so you suggest that for now, we only applied //+ignore when the module is called from the CLI?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it fixed the issue! I'm trying to get the CI green and then we can do the ignore process in a follow up

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I disagree here - I think the filtering twice is frustrating from a performance point of view, but I'd rather that than have entirely different behavior when invoking from the CLI vs from another module.

Is your concern just performance @helderco? Or is there a correctness concern here as well?


As a suggestion, the way to track this would be add a field to Directorys that indicate which ignore patterns were used during resolveDirectoryFromCaller. Then we just check if those were equal to the patterns specified here, and if they are, we can skip the applyIgnoreOnDir.

This should be pretty simple, it just needs to be plumbed through?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I disagree here - I think the filtering twice is frustrating from a performance point of view, but I'd rather that than have entirely different behavior when invoking from the CLI vs from another module.

That's fair, I'm just willing to release filtering from the CLI first depending on how long it will take to handle both use cases correctly since I think that's much more important and immediately useful to people. It's at the boundary from host to engine, so that's where users are reporting issues with slowness.

Is your concern just performance @helderco? Or is there a correctness concern here as well?

There's a correctness concern, yes. I was going to ask some questions on the implementation but noticed it was the cause of the failing checks due to sdk/python/dev.

There's also the performance concern, but only secondary. The main problem for me there is that it forces a copy (withDirectory), so for users with big directories this could be quite noticeable. I know withDirectory can do a mergeOp if the path in both directories is /. Maybe it is that, when using resolveFromCaller, but haven't actually checked or tested with a big file.

As a suggestion, the way to track this would be add a field to Directorys that indicate which ignore patterns were used during resolveDirectoryFromCaller. Then we just check if those were equal to the patterns specified here, and if they are, we can skip the applyIgnoreOnDir.

Yeah, I suggested the same thing in sync last week.

This should be pretty simple, it just needs to be plumbed through?

Yeah, I'm all for it if @TomChv can make both work not only correctly (i.e., even if filtered twice, there should be no difference in the result), but also without the performance hit on the copy for heavy directories.

Comment thread core/schema/modulesource.go Outdated
Comment on lines +1269 to +1273
if len(args.Ignore) > 0 {
excludes = append(excludes, args.Ignore...)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good idea. When specifying a view:

dagger call --source=.:default source

This code is adding the patterns from the view, with different semantics from // +ignore because of the split into exclude/include based on !, and adding the // +ignore patterns on top.

I think it's less surprising if you apply one or the other. Basically let a view override the patterns from code, instead of acting as a default.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is adding the patterns from the view, with different semantics from // +ignore because of the split into exclude/include based on !, and adding the // +ignore patterns on top.

And also because orders matter, it might totally break the expect result.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly.

@TomChv

TomChv commented Sep 18, 2024

Copy link
Copy Markdown
Member Author

I'm trying your suggestion, see if it fixes my issues

@TomChv TomChv modified the milestones: v0.13.1, v0.13.2 Sep 19, 2024
@helderco helderco changed the title feat: apply ignore metadata on any directory feat: apply ignore metadata on directory flags from the CLI Sep 19, 2024
Comment thread core/modfunc.go Outdated
Comment on lines +140 to +146
// Disable for now until we figure out how to not "double-ignore" arguments from CLI
// if len(arg.metadata.Ignore) > 0 {
// converted, err = fn.applyIgnoreOnDir(ctx, opts.Server, arg.metadata, converted)
// if err != nil {
// return nil, fmt.Errorf("failed to apply ignore pattern on arg %q: %w", input.Name, err)
// }
// }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we disabling this?

What's the issue with the double-ignore? My expectation is that this would work right? It's just that we would not actually end-up excluding things, so it's slightly worse performance, but it would still do the expected thing right?

If it's just that, we should enable it, leave a note, and come back and optimize later by fixing the "double-ignore" issue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of this: #8436 (comment), but I think I'll just remove that part of the code since I talked with Helder and he said it wasn't very important to support ignore in module to module

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in d974dcb, supporting ignore from module to module will be done in a follow up later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we disabling this?

The implementation didn't seem to correctly handle the ignore patterns in /sdk/python/dev when used as a dependency in /.dagger (missing pyproject.toml for example). I suggested releasing the CLI use case first, depending on how long it would take to do this properly for all directories, since users are reporting slowness there.

Comment thread core/modfunc.go Outdated
return nil
}

// func (fn *ModuleFunction) applyIgnoreOnDir(ctx context.Context, dag *dagql.Server, arg *FunctionArg, value any) (any, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid committing commented code - it simply ends up getting out of date with the rest of the code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll remove it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the commented code in d974dcb

body: |-
Apply `ignore` function parameter metadata on any Directory passed from the CLI.

This extends the usage of `ignore` to not only dir loaded with `defaultPath` but any directory passed as function's param.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #8436 (comment) - I think we should ship both of these together, it's a weird functionality gap to only do one of them (especially given it doesn't seem tricky to do them at the same time?)

But if we decide to ship them separately, then this sentence should be rephrased for clarity - it's not any directory passed as a function param, it's only for directories passed on the CLI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(especially given it doesn't seem tricky to do them at the same time?)

Yes the function I did was quite simple but it broke all the tests for a weird reason where python had missing file, Helder suggested to disable the double ignore and it fixed the issue.

I'll update the release note

@TomChv
TomChv requested review from helderco and jedevc September 20, 2024 10:36
@vito vito removed this from the v0.13.2 milestone Sep 20, 2024
@TomChv

TomChv commented Sep 23, 2024

Copy link
Copy Markdown
Member Author

@jedevc jedevc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, won't block on a full module implementation - but we should follow-up with the asap.

@TomChv
TomChv force-pushed the feat/apply-ignore-on-any-dir-source branch from c10302b to 4341cc5 Compare September 23, 2024 16:09
@TomChv

TomChv commented Sep 23, 2024

Copy link
Copy Markdown
Member Author
Screenshot 2024-09-23 at 18 28 45 Lint is good locally, so guess it was a flack, gonna run the CI until it's green so I can merge that one

Tom Chauveau added 16 commits September 24, 2024 10:30
Update `ModuleFunction.setCallInputs` to apply ignore patterns on
`Directory` that have `ignore` as metadatas.
Update `ResolveDirectoryFromCaller` arguments to supports optional
ignore argument.
Update CLI `Directory` handling to also apply ignore on Directory
if `ignore` is set.

Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat/apply-ignore-on-any-dir-source branch from 4341cc5 to dbd0539 Compare September 24, 2024 08:30
@TomChv
TomChv merged commit 7fb1fb8 into dagger:main Sep 24, 2024
@TomChv
TomChv deleted the feat/apply-ignore-on-any-dir-source branch September 24, 2024 09:21
@coderabbitai coderabbitai Bot mentioned this pull request Aug 12, 2026
10 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Apply ignore patterns from Directory argument in dagger call

4 participants