Skip to content

cmd/cue: support $pkg@$version specification of packages #3618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
myitcv opened this issue Dec 7, 2024 · 0 comments
Closed

cmd/cue: support $pkg@$version specification of packages #3618

myitcv opened this issue Dec 7, 2024 · 0 comments
Labels
FeatureRequest New feature or request

Comments

@myitcv
Copy link
Member

myitcv commented Dec 7, 2024

What version of CUE are you using (cue version)?

$ cue version
cue version v0.0.0-20241204160345-46c1cb24b09b

go version go1.23.2
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS linux
         GOARM64 v8.0
             vcs git
    vcs.revision 46c1cb24b09b3981a5a7e585cba80cabfa8bc8e2
        vcs.time 2024-12-04T16:03:45Z
    vcs.modified false
cue.lang.version v0.12.0

Is your feature request related to a problem? Please describe.

It is proving to be common to want to refer to a package in version of a published CUE module but not be module context when doing so. This is possible in Go, for example:

$ go run golang.org/x/tools/cmd/[email protected] -help
go: downloading golang.org/x/tools v0.28.0

The digraph command performs queries over unlabelled directed graphs
represented in text form.  It is intended to integrate nicely with
typical UNIX command pipelines.

Usage:

        your-application | digraph [command]

...

This command can be run anywhere, and requires/uses zero context from the working directory: it only relies on the configuration described by go env.

Having something similar in CUE would allow:

  • "Standalone" validation of data files, e.g. cue vet $pkg@$version -d '#schema' data.yaml
  • Plain evaluation/export of published packages at known versions, providing reproducible output, e.g. cue export $pkg@$version -e part.of.config

Describe the solution you'd like

The ability to run cue/cmd commands with a package specification of $pkg@$version, where $pkg is a fully qualified package path, and $version is a semver version or a version query like @latest.

Describe alternatives you've considered

The alternative requires:

  • setting up a temporary local main module
  • establishing dependencies
  • running commands there against the main module's dependency

Additional context

n/a

@myitcv myitcv added the FeatureRequest New feature or request label Dec 7, 2024
cueckoo pushed a commit that referenced this issue Mar 21, 2025
To support package paths like `foo.com/[email protected]` and `@latest`,
we'll need to recognize those paths as packages, so change
filetypes.IsPackage to do so.

For #3618.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: If48f8821ca48680d146b9ffd778a529d19af4483
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211883
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Mar 21, 2025
This adds a method to the registry cache to enable fetching
from the cache directly without falling back to registry access.
This will be used as the fast path for looking up modules
by their absolute version without the need to check
all path prefixes in the registry.

We want the `modload` package to be able to depend on this
logic, so avoid the need for modcache to depend on modload
by exporting the concrete type instead of the interface type.

Also define an interface type for the new cache method so
we can potentially have different kinds of cache implementations
in the future.

Also document the error return of the `Fetch` and the
new `FetchFromCache` methods so that we can distinguish
between "module not present" and other errors.

For #3618.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Idf713910ccb7f09b0c43c125281171dfb5638866
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211884
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Mar 21, 2025
These tests ensure that we can use ParseImportPath
to parse the new query syntax. No logic changes were
necessary, but it's good to be explicit that this works.

For #3618.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I89e170006bb9ad5d2597294dfd65d4ccecd97ce4
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211885
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
cueckoo pushed a commit that referenced this issue Mar 21, 2025
This factors out some of the logic that was previously internal to
Packages.importFromModules into a place where it can
be reused to find a module for an absolute import path.

Also define a `PackageLoc` type to make it more convenient
to return a slice of package locations.

While we're about here, remove the unused `altMods` field.

For #3618.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Ia15d6447a75a6f979a02edb313da57d1fedb0962
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211886
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
cueckoo pushed a commit that referenced this issue Mar 21, 2025
This allows us to look up the module for a package that's specified in
absolute terms, independently of a main module.

For #3618.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I004f1b3f3af16d31b252869462471416f3647a74
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211887
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant