Skip to content

Zenith: handle local module dependency being outside directory tree #5862

Closed

Description

@sipsma

We need to handle a local module dependency being outside the directory tree of the depender (i.e. path that uses ../)

Activity

  1. jedevc commented on Oct 11, 2023

    @jedevc
    Contributor

    Ok, so actually you kinda can do this already, just in a fairly confusing way:

    Imagine a current directory with a foo and bar module. If we want bar to import foo, we can:

    {
      "name": "bar",
      "sdk": "go",
      "sdkRuntime": "vito/dagger-sdk-go:no-ptrs@sha256:2bb26bae3f30b920a4530b7495127fe4986102b06a99ff170500e83c25739b27",
      "root": "..",
      "dependencies": [
        "../foo"
      ]
    }

    By setting the root to the directory above, we load the entire current directory, which lets that path lookup happen.

    However, this is a bit confusing IMO - I would actually expect for local dependencies to be resolved relative to the root. On the other hand - it would be nice if we didn't have to set root at all and dependencies were just resolved relative to the directory of the module - but this would kind of violate the niceness of "just load a module from this directory".

    I think we could load relative to the root quite simply by just modifying

    depConfigPath = modules.NormalizeConfigPath(path.Join("/", path.Dir(configPath), modRef.Path))

    This could just be updated to resolve entirely relative to the root.

  2. sipsma commented on Oct 14, 2023

    @sipsma
    ContributorAuthor

    @jedevc The idea of root is really just meant to handle the case where you have something like go.mod/package.json/etc. in a parent directory but your code can't run without it.

    I think I'd prefer to keep its usage exclusively to that. Perhaps to the point where we should rename it to something hyper-specific like requiredParentLoadDir (don't like that name, just a strawman).

    The reason being that it's inherently sort of confusing and not pleasant to work with and think about. It only exists out of necessity.

    Along those lines, I think that resolving dependencies relative to root would deepen the confusion since now you have to mentally join together two separate paths to figure out where you're supposed to point to.


    That being said, there is going to be something of an interaction between support for a dependency being out-of-tree an root, since root is currently how we decide what to load into the engine in the first place.

    One possibility would be to look at the paths of dependencies and use those in combination with root to figure out what we need to load to get everything we'll need. The internal complexity would be sad since we'll still need to keep the behavior of "root" the same as today, but I suspect it would result in the most easy to understand behavior for end-users.

    Let me know if any of this makes sense 😅I'm going through a lot issues right now so my attempts at explanation here is a bit rushed

  3. jedevc commented on Nov 7, 2023

    @jedevc
    Contributor

    That being said, there is going to be something of an interaction between support for a dependency being out-of-tree an root, since root is currently how we decide what to load into the engine in the first place.

    Ok, so I dug into this as part of #6086. This just tries to hard-enforce how this works today, I actually think it's pretty reasonable with a bit more error prompting (why can't I load "../foo", oh it's not part of my root) and docs work.

    One possibility would be to look at the paths of dependencies and use those in combination with root to figure out what we need to load to get everything we'll need. The internal complexity would be sad

    Ahh, so my worry with this is that if we do this, users may attempt something like:

    {
      ...
      "dependencies": [
        "../../../../home/otheruser/modules"
      ]
    }

    Obviously a bit exaggerated - but the issue here is that we'd end up loading the entire root directory (since that could be the only common directory between that module and ours). If a user wants that behavior, they should be required to put the target directory in the "root" field. Potentially we could do something here and create a "sparse" tree, and only include the contents of the requested modules (preserving the structure correctly).

  4. sipsma commented on Nov 13, 2023

    @sipsma
    ContributorAuthor

    Potentially we could do something here and create a "sparse" tree, and only include the contents of the requested modules (preserving the structure correctly).

    Yes that's what I was imagining; we can do it with the right include/exclude opts I believe.

    Honestly, the thought of how complicated that would get in our internal code makes me inclined to wait for users actually request this rather than jump right into it. But I do suspect it will come up in monorepo-type use cases where one module may want a dep on another that lives in a totally different part of the tree, but they also don't want to load the entire "root" either.

  5. jedevc commented on Nov 14, 2023

    @jedevc
    Contributor

    Honestly, the thought of how complicated that would get in our internal code makes me inclined to wait for users actually request this rather than jump right into it.

    Massive +1 on this, I think #6086 gets us close enough for now, we can park this until someone asks for it 🎉

  6. sipsma commented on Feb 21, 2024

    @sipsma
    ContributorAuthor

    This was done in #6575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions