Skip to content

Don't re-use project go.mod on init. - #8095

Merged
jedevc merged 3 commits into
dagger:mainfrom
marcosnils:marcos/dev-4188-dont-reuse-parent-gomod-by-default
Aug 15, 2024
Merged

jedevc merged 3 commits into
dagger:mainfrom
marcosnils:marcos/dev-4188-dont-reuse-parent-gomod-by-default

Conversation

@marcosnils

@marcosnils marcosnils commented Aug 2, 2024 •

Copy link
Copy Markdown
Contributor

Fixes #7527

Signed-off-by: Marcos Lilljedahl [email protected]

@marcosnils
marcosnils force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch from b1c342b to d17d59b Compare August 3, 2024 11:50
@marcosnils marcosnils changed the title wip Don't re-use project go.mod on init. Aug 3, 2024
@marcosnils
marcosnils force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch 5 times, most recently from a27ffca to 8712f50 Compare August 5, 2024 15:13
@marcosnils
marcosnils marked this pull request as ready for review August 5, 2024 15:14
@marcosnils
marcosnils requested review from a team as code owners August 5, 2024 15:14
@marcosnils
marcosnils requested review from helderco and jedevc August 5, 2024 15:14
@marcosnils

marcosnils commented Aug 5, 2024 •

Copy link
Copy Markdown
Contributor Author

This should be good for a fist pass. cc @helderco @jedevc

edit: tests failures seem a flake as they pass locally.

Comment thread cmd/dagger/module.go
moduleInitCmd.Flags().StringVar(&moduleSourcePath, "source", "", "Source directory used by the installed SDK. Defaults to module root")
moduleInitCmd.Flags().StringVar(&licenseID, "license", defaultLicense, "License identifier to generate. See https://spdx.org/licenses/")
moduleInitCmd.Flags().BoolVar(&mergeDeps, "merge", false, "Merge module dependencies with existing project ones")
moduleInitCmd.Flags().MarkHidden("merge")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

marking this as hidden as a fallback in case users need to override this behavior. Not entirely sure if we should un-hide it. Thoughts?

@jedevc jedevc Aug 9, 2024 •

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'm actually not sure about this option at all. (It's also a bit weird to have a go sdk specific flag right here, if we do want to have it, we probably want to make it a bit more generic or hide it if --sdk=go isn't set).

I think we should probably default to always generating go.mod/go.sum. If the user doesn't want them, they can delete them after, right? As long as we have a test for that, and check it works as expected and gets merged into the root, I think that's fine.

That way, go is like all the other sdks, which manage their own dependencies.

I might be wrong, maybe we do need to keep this option - WDYT @sipsma?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The feedback about allowing backwards compatibility with a flag came from @shykes https://discord.com/channels/707636530424053791/1003718839739105300/1266140398112346203.

I'd have preferred to avoid it since it makes the implementation cleaner but on the other hand I understand the reason to add it also.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if we do want to have it, we probably want to make it a bit more generic or hide it if --sdk=go isn't set).

The flag is hidden by default, so users won't know it's there. It's mostly a "safeguard" in case someone is trying to get the current "merge by default" behavior. IMO it's very unlikely to happen, but if it does, we can tell them to use this hidden flag.

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.

Yeah okay, I guess a flag isn't too bad 🤷‍♀️ But, we should have a way of explicitly erroring in python/typescript/etc if --merge is set - maybe one day they could be set with merged dependencies, but I don't think that's the behavior today, and I don't think it's configurable (cc @helderco @TomChv).

(Ideally this check should be in the SDK! Not the CLI).

After merging, we should consider either:

  • Update Remove deprecated APIs in v0.13.0 #8065 to discuss removing the flag (if we wanna go that route)
  • Opening a follow-up issue to implement something similar in python/typescript if we wanna keep this flag around indefinitely

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.

As long as the flag is hidden, we can wait for someone to ask for it, and if nobody does, we'll just remove it.

@helderco
helderco requested a review from sipsma August 7, 2024 12:48
@marcosnils marcosnils added this to the v0.12.5 milestone Aug 7, 2024
Comment thread sdk/elixir/mix.lock Resolved
@marcosnils
marcosnils force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch 3 times, most recently from b28dc5f to d71324b Compare August 14, 2024 14:01
Comment thread core/schema/module.go
Comment on lines +923 to +927
if src.Self.WithInitConfig != nil &&
src.Self.WithInitConfig.Merge &&
mod.SDKConfig != SDKGo {
return fmt.Errorf("merge is only supported for Go SDKs")
}

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.

Not hugely in love with this check being here, ideally we would propagate all the WithInitConfig options into the module SDKs as well, and they would be able to handle them.

However, yeah, it's fine to not do that for now - the plumbing is definitely fiddly 😢 (and maybe actually requires module introspection, separately from codegen, which I'm doing as part of the dag.Self work).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, agree 😬

// will want to have a runtime module that lives in the same Go module as
// the generated client, which typically lives in the parent directory.
if mod == nil {
if mod == nil && (g.Config.Merge == nil || *g.Config.Merge) {

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.

Should this not be (g.Config.Merge && *g.Config.Merge)? If g.Config is nil, we should assume merge is false right?

@marcosnils marcosnils Aug 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

g.Config can't be nil since it's not a pointer.

Should this not be (g.Config.Merge && *g.Config.Merge)

this doesn't evaluate as g.Config.Merge is *bool

the reason behind this condition is to only perform the block below if mod ==nil AND merge is not set (which dagger init should always set), or it's set to true

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.

Sorry, I mean - g.Config.Merge == nil shouldn't be assumed to be true? If it's nil, shouldn't it be false? That keeps zero-ish values roughly equivalent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it's nil, shouldn't it be false?

Not really since "not set" (g.Config.Merge == nil) doesn't have the same meaning as set to false. That's the main reason for making it a *bool and not passing the flag directly here https://github.com/dagger/dagger/pull/8095/files#diff-fc3b73c833f27945a9663b13ce2651daa11e86389d062a3468e2e038d14d2d6aR66-R68.

I'll add a comment in that line.

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.

Can we handle this and remove the pointer at that point then? I don't understand why we need to have it be a trinary setting.

The conditions where we use it, g.Config.Merge != nil && !*g.Config.Merge and g.Config.Merge == nil || *g.Config.Merge, are just the inverse of each other (by De Morgan's).

@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.

Left some comments, but once resolved and tests pass LGTM 🎉

@marcosnils
marcosnils force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch 2 times, most recently from b88607c to a69b6f9 Compare August 14, 2024 15:10
This allows setting init configurations to ModuleSource so they can be
passed over between  the different layers of the codegen. This commit
adds a new `merge` config which allows to set if the module dependencies
should be merged with the main project upon module initialization.

Signed-off-by: Marcos Lilljedahl <[email protected]>
@jedevc
jedevc force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch 2 times, most recently from 96c5218 to 5f3813a Compare August 15, 2024 13:00
@jedevc
jedevc force-pushed the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch from 5f3813a to e2e6583 Compare August 15, 2024 13:07
@jedevc
jedevc merged commit 76765fb into dagger:main Aug 15, 2024
@marcosnils
marcosnils deleted the marcos/dev-4188-dont-reuse-parent-gomod-by-default branch August 15, 2024 14:16
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.

Don't reuse parent go.mod by default

3 participants