Repository navigation
simplify module config UX via automatic sparse loading of required files - #6575
Conversation
2604b93 to
65151c0
Compare
e643298 to
eb960ee
Compare
What's the arguments/use cases for this default? |
@helderco |
|
Hm, I have to agree with @helderco - I think Actually, the most "expected" option for me as a user would be to default to That said, I'm also happy with |
helderco
left a comment
There was a problem hiding this comment.
Mostly improvements to --help for now, so people don't depend on docs to learn. It took quite a bit of experimenting (dagger init still) to understand how it all plays together.
It takes some getting used to the behavior of using from "root", since I was used to have modules all over, but once you do I think it makes sense.
However, the default of dagger/<sdk> for --source doesn't sit well. Prefer just dagger or .dagger. I don't think changing the SDK would be something common by any stretch. I'd just create a new one.
There was a problem hiding this comment.
Won't this include sdk/pyproject.toml? Only need the one at the root of source dir.
There was a problem hiding this comment.
It will yeah, but I think what we'd optimally want is the "nearest" one in any parent dir in the context directory (I'm assuming pyproject.toml has similar-ish behavior to go.mod/package.json/etc.). To do that we'll need even more intelligence.
My first thought was something like actually giving this SDK function ModuleSource so the SDK can inspect it. The problem there is we are lazily loading these dirs, so we actually couldn't give SDKs plain old Directory, we'd need to give them some object that lets them stat + read files from the caller's host. Which is do-able technically but too much for here.
There's probably other ways of approaching this like allowing the SDK to return something that conveys i.e. "give me any file with this name from the nearest parent dir above the source dir" and then let the engine do the rest.
Either way, all that felt like excessive optimization for now, so I just went with this approach. Can optimize more in the future as needed.
There was a problem hiding this comment.
Since all files from source dir are already included, I think I'll remove this until a use case presents itself. To be useful, it'd have to be configurable by the modules.
There was a problem hiding this comment.
Cool sounds good, I do see now that there's no subtest under TestModulePythonInit like respects parent pyproject.toml, so I guess it's different than go/ts right now
One thing to clarify is that it's still completely valid to put modules all over the place as it was previously. It's actually easier than ever to do that because you don't have to contend with calling
|
Yes, I said it took "getting used to" because of the change in defaults. Felt more "distributed" and now it feels more "centralized". 🙂 I'll still want to add Being able to set the target dir is great! 🙌 Really disliked all the But if |
This is true, but I still feel pretty strongly that it's worth being consistent here even if it can result in more verbosity for situations like that. All this path arithmetic is a huge headache to think about and easy to mess up so I'd rather we just have a consistent model of "paths are relative to your cwd". Also works better with |
jedevc
left a comment
There was a problem hiding this comment.
I like the described changes, and nothing stands out immediately as weird in the code 🎉
That said, this is a several thousand line diff - so don't really have the time to dig through all of this line-by-line, but... LGTM!
Of course, I agree. |
There was a problem hiding this comment.
Since dagger init defaults name to the parent dir, when would it be empty by dagger develop time?
There was a problem hiding this comment.
Yeah I suppose that first check for "" is probably redundant other than obscure cases like hand-edited dagger.json. It's also not hurting anything either and makes this slightly more resilient to those obscure cases, so I'm inclined to leave it as is.
There was a problem hiding this comment.
Actually while I was updating from your other comments I realized this is totally dumb and we probably just shouldn't even have --name in the first place on develop, at least until we actually support renaming a module that already has one set. Any obscure benefits are greatly outweighed by giving users the wrong impression they can actually use develop --name its current state. Gonna switch to that instead.
There was a problem hiding this comment.
| Use: "develop [--name string --sdk string] [--source string]", | |
| Use: "develop", |
There was a problem hiding this comment.
Maybe require --sdk if there's no source/code.
There was a problem hiding this comment.
--source default here is diff from init.
There was a problem hiding this comment.
Maybe require --sdk if there's no source/code.
Yeah that makes sense, would be confusing to silently do nothing. Fixing.
--source default here is diff from init.
Good catch, cleaned up all this logic a bit more and fixing that.
There was a problem hiding this comment.
Could maybe use the opposite of this, i.e., exclude sets of files. Each language as their own common .gitignore globs.
There was a problem hiding this comment.
The behavior of include/exclude (as we inherit from buildkit) is actually that if anything is provided in include, that results in everything else being discluded. So when we specify include we're saying only include those files. Which actually is exactly what we want here; ignore everything unless told not to 🙂
helderco
left a comment
There was a problem hiding this comment.
Looks good overall 🙂 My comments amount to mostly polish. In the interest of unblocking this, I'll approve now. We can polish later if you're out of time.
vito
left a comment
There was a problem hiding this comment.
Mostly reviewed DagQL related changes, been following the discussion and I'm in agreement with the current state of things - LGTM!
There was a problem hiding this comment.
The With prefixes here feel a little confusing, since they'd clash with the methods I imagine you would use to set them. I guess these are distinctly named to indicate they're overrides to apply to the original module?
There was a problem hiding this comment.
I guess these are distinctly named to indicate they're overrides to apply to the original module?
Yeah we do want to track them separately from the original values for various reasons:
- knowing the original name is important because it should always be used for codegen, with the override name only impacting the schema of those depending on it
- knowing the original dependencies is important since we de-dupe deps by symbolic ref with a preference for the ones specified in
WithDependencies - etc.
I'm trying to think of a better name. OverrideName/etc. feels wrong too these also are used when there wasn't an original value in the first place. If I think of something I'll update but otherwise leave it for now. There's a comment right above these lines explaining them if nothing else 😅
There was a problem hiding this comment.
Ah so this is the tricky part. Definitely a bit awkward, but this is the price you pay for reproducible pipelines, I guess.
Does this only affect local module sources? For example, if I ran with -m pointing to a Git ref, will the resulting ID's module still reference git like normal and keep all the nice theoretical portability properties? (I think the answer is yes, but just making sure.)
There was a problem hiding this comment.
Does this only affect local module sources? For example, if I ran with -m pointing to a Git ref, will the resulting ID's module still reference git like normal and keep all the nice theoretical portability properties? (I think the answer is yes, but just making sure.)
Yep only local sources right now. Git sources are inherently normalized like you said, much easier to deal with 😄
|
Thank you everyone for the reviews! I am making updates discussed above about having --source always be relative cwd (lots of fun corner cases), but very small change. After that I'll update based on the rest of the comments and merge 🚢 |
Signed-off-by: Erik Sipsma <[email protected]> Co-authored-by: Alex Suraci <[email protected]> Co-authored-by: Erik Sipsma <[email protected]>
This started as a fix to a problem where syncing a module using
"include" in dagger.json was resulting in the dagger.json being reset to
an empty module. The root cause was that the include did not have
dagger.json itself in it, so when the module was loaded into the engine
it looked like an uninitialized module that needed to be initialized.
That bug in particular was a regression caused by the recent changes
around module loading and configuration.
This change fixes that bug, but along the way I realized there's quite a
few pre-existing issues that have existed since forever around
include/exclude too. It's too much to squash all at once, but I went with
an approach that will set us up to fix those in further iterations and
should make it possible to implement some loading optimizations around
huge monorepos we've discussed previously.
The other pre-existing issues are:
* Include/exclude settings apply to source files like main.go,
src/main.py, src/index.ts, etc.
* This one in particular is fixed in this change. A new Function,
`requiredPaths` is added to the SDK interface that lets SDKs tell
the engine which files should always be loaded.
* Include/exclude settings apply to local dependencies (and local custom
SDKs), which I'd consider surprising enough to be a bug. It would be
expected that if you configure a local dependency, that acts as an
implicit include of it.
* Include/exclude settings of local dependencies are ignored, only the
top level module's include/excludes are actually impactful in terms
of what's loaded.
* Exclude in particular overrides any include settings, including all
essential files (still the case after this change).
The approach I went with here centralizes even more loading logic in the
engine. There's a new field on LocalModuleSource called
resolveFromCaller that uses the filesync API to do all of the find-up
logic, config reading/parsing and directory loading for the caller from
the engine. The CLI (or any other SDK user) can now load modules from
their local filesystem with just that API rather than doing the whole
dance themselves.
This approach is beneficial for a few reasons:
1. There's less logic to keep in sync between the engine and the CLI.
Similarly, local module loading is re-usable beyond just the CLI now
2. Fixing the problem around files like main.go, src/main.py, etc. not
being loaded required adding a new function to the SDK interface. The
CLI could have been exposed to that, but it would have continued to
make its logic even more complicated, especially around the case of
custom local SDKs.
3. In the future, fixing the rest of the pre-existing issues listed
above would also have deepened the complexity of the CLI's logic
much, much further (while also requiring the engine-side loading of
dependencies to have its own version of the same logic).
4. This sets us up for optimizations we've discusssed previously around
loading large sets of dependencies from monorepos, which again
requires complex logic that's better centralized in the engine.
It's still entirely possible for SDKs to just load up a local directory
as a module if they want; that API is not removed. It's just not
required they implement complex custom loading logic that is required to
get everything working correctly+optimally.
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
This is a bit of hack atm but enough to unblock the only use case for it. Can be generalized as needed. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
34ef45f to
4e876e0
Compare
Signed-off-by: Erik Sipsma <[email protected]>
Goals
.gitand otherwise default to the source root path specified so everything stays sandboxeddagger initin the right place, there's noroot/root-for/etc. settings, etc.dagger init --source <path>anddagger develop --source <path>for customizing the subdirs at which actual module source code is located--sourcedefaults todagger/. See this discord thread for discussion on the default value.Example Usage
--sourceusageOne of the primary use cases
--sourceas an arg toinit/developenables is puttingdagger.jsonin the root of a repo without necessarily polluting the root with SDK source files, e.g.dagger init --name foodagger.jsonis created in your cwd by default, so in this case it's in the root of the repodagger installto add some depsdagger develop --sdk=go --source=some/subdirmain.goand other go sdk files at undersome/subdirin the repodagger.jsonis also updated to set"source": "some/subdir"--sourcehadn't been specified, it would have defaulteddagger/go(with the last element always being set to the name of the sdk)--source=.is valid too still, just not the defaultdagger call foofunc ...from the rootgit clone'ing your daggerized repo for the first timedagger install github./com/org/repois enough since they just need to point to the root of the repoThis is just one use case, generally speaking the goal here is to be flexible while retaining sane defaults and sandboxing everything to the
.gitcontext.Terminology
Contextgo.mod/package.json/etc. from parent dirs and to load any deps/custom sdks/etc. local to the module.git(or the dir containingdagger.jsonas a fallback)Source Root PathContext(or the same as it) that containsdagger.jsonfor a module.dagger call -m github.com/foo/bar/the/sourceroot ...Source Pathmain.go,src/index.ts,src/main.py, etc.)--sourceand defaults todagger/(see above sections for more usage details)Implementation notes
RequireFilesthat allows them to specify which files they need in order to load (i.e.go.modis one required by the go SDK)ModuleSourcearg and used it to determine very precisely what's needed (i.e. right now we require**/go.modbut really we only needs ones that are in parent dirs or are referenced by those in parent dirs). But saving that optimization for the future.dagger.jsonfrom each one. Code.gitfrom the engine code. CodeModule/ModuleSourceAPI, though it amounted to mostly re-arranging rather than anything new besides the sparse loading logicWithName/WithSDK/WithDependenciesmoved fromModuletoModuleSource. This was required because those apis can actually change what is required from the context and trying to later re-load those files from their original source while also keeping source IDs pure was practically speaking not really possible.ModuleSourceand onceAsModuleis called it's immutable