-
Notifications
You must be signed in to change notification settings - Fork 299
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
tooling: native embed and export #2031
Comments
Previous brainstorming with @mpvl around use case 1 resulted in the following ideas:
Use case 2 could similar be solved via attributes:
|
I took the time to read about the Go embed package which was enlightening. One of the main differences for Go and CUE is that the there is a set compile step for programming language (where Go can embed data into a program). With CUE, that timing is not clear, and CUE users may want control of when IO happens. |
Question: One point that is unclear is when the syncing IO happens, since would that not be a violation of CUE hermiticity? |
Answered by @mpvl:
|
For the attributes arguments, I think taking protocol schemas would be more flexible eg I think designing it this way allows for more schemes in the future that are not based on reading from the filesystem but also network/database. For example a scheme to embed data from a remote system using the query language to pick out the 'subgraph` Referring to |
As discussed offline, we definitely want/need to support specifying the filetype in some way. However, using a URI scheme has (to my mind at least) the unfortunate side effect of suggesting we support (module) absolute paths. Using the Go
|
personally, i'm also open to an ultra-simplified variant where you can only embed/import to an unevaluated string these should just load and error like any other value, outside of tools (which separates this use case).
|
Adding a further note here: this solution should at least consider the case presented in #2346. |
Also noting an exchange with @kghenderson in which he observed there is a parallel between the concept of |
An One use case we have, though, involves extracting data from CRDs - current we use
or something? Maybe what's called for is an extra tag -
Alternatively, maybe it wants to be The critical thing, I think, is that I have (in this case) JSONSchema embedded in YAML, so to work with it in CUE, I'd want to |
Thanks for the use case, @nyarly. I think that fits with a later iteration of I'm tentatively marking an initial version of this proposal as v0.7.0, pending working on a design draft with @mpvl and @rogpeppe this week at KubeCon EU. The initial version would be The main goal of the design draft for the initial version is:
The second point is key. We should not preclude the kind of syntactic sugar that @nyarly imagines above, and that we have speculated about in the original notes in this discussion. Because ultimately it should, for example, be possible and easy for someone to say "embed this file at this point treating its contents as JSON". |
Adding an observation here related to |
Milestone moved to v0.7.x, in order that we focus on performance and disjunction related changes first in the v0.7 series, and that get to this whilst people are trying out early alphas of v0.7.0. |
Any further progress to share on this? |
@mpvl is currently entirely focussed on performance work as part of the evaluator rewrite. See #2850 for the ~fortnightly updates on progress on that front. When work on that front settles we are going to publish a design doc/proposal on how native embed will work with CUE, along with an experimental implementation. |
Exposing ParseFileAndType. For the embedding proposal, file and type are specfied separately and do not need to be parsed as on the command line. Issue #2031 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Ib02f845d503edf1d78834a1ff2a0c224cc936748 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196716 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Right now, we only allow one type of extern attribute in a file. At the file level, we define @extern(kind). Fields within the file can then be associated with an @extern attribute that is interpreted as defined by kind. This approach may work for lower-level functionality like support for WASM, but it seems a bit unintuitive for embed. Instead, we suggest that after a file-level @extern(kind) declaration the field attributes take the form @kind(). This is what is implemented here. This has the additional benefit that we could more easily allow different types of extern fields within a single file. Note that the original reason to reuse @extern for field attributes was to avoid a proliferation of attributes. This namespace encrouching is still a bit mitigated by the @extern(kind) attribute. In the future we can find a different mechanism to define attributes scoped by domain. Issue #2031 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: I28b1fdd0f0a85c46a544f71bbff40a7772e60873 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196717 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
This is a first-stab and partial implementation of the embedding proposal. See the TODO list included in embed.go to see what is outstanding. Issue #2031 This issue is not closed, as it also referes to the complementary export attribute. Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Ic296a28aa009509f9a17913c7e5a0794de5a7a35 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196718 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Aram Hăvărneanu <aram@cue.works> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
This could later be allowed as an option. This is a security feature. We also disallow hidden files on Windows for the same reason, which is a bit more involved. Note that this results in potentially slightly different behavior under Windows and Unix. This is already the case. For instance, the set of valid filenames is different on the different supported OSes. So we accept this discrepancy in favor of added security. Verified that without adding the new logic, the hidden file that was added to embed.txtar gets included in the output. Issue #2031 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: Iacff803f4c388d1f2792665ed5adb32f68f00ffa Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196775 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
As part of the v0.10.0-alpha.1 release, we have just published an embed proposal #3264. Please give it a try out. We would very much welcome feedback via the linked discussion. |
Adding a drive-by comment regarding the hypothesised Indeed the |
A further drive-by comment on the hypothesised
In the pseudo-code above, I have marked the "inner" value for the Note: this pseudo-code is not a suggested design/syntax/etc, instead hopefully a simple means of indicating that the resulting contents of I suspect this requirement extends more generally to other situations. |
Two very common use cases are:
cue import -l "$path"
to "place" some JSON/Yaml/... at a given path in a CUE configuration.cue export -e "$expr" --out $format
to take part of a CUE wider config graph and export it to JSON/Yaml/... ready for consumption by a non-CUE tool/system.(Here,
$path
is a shell-like variable syntax used to indicate "some path", similarly for$expr
standing in for "some CUE expression").Note that whilst in some situations both use cases appear in tandem, this is not a requirement. The two use cases are orthogonal.
If use case 1 were a one-off import to CUE, it would be relatively straightforward to run
cue import
and be done, removing the original JSON/Yaml file. However, in some situations it be necessary to leave the original JSON/Yaml file as the source of truth. For example, if some other process generates/maintains that file. In this scenario, it becomes a burden to have to repeatedly re-runcue import
to ensure that the CUE configuration is current with respect to the source JSON/Yaml.In a similar way, use case 2 is in practice never a one-off command. If CUE is being used to maintain the source of truth for the target tool/system, then
cue export
will need to be run on every change of the source CUE to ensure that the target tool/system sourcing the output JSON/Yaml reads a current version. The burden in this scenario comes from needing to maintain multiplecue export
commands somewhere, either in a bash script/similar, or acue cmd
script. Whilst thecue cmd
solution will absolutely work there are two drawbacks:cue cmd
command is incredibly verbose.This issue tracks adding support for a more native embed (use case 1) and export (use case 2) facility.
The word "embed" draws inspiration from Go's
embed
, and the use of//go:embed
directives. It is likely desirable that CUE support a similar directive (comment)-based approach for both use cases 1 and 2.The text was updated successfully, but these errors were encountered: