Add starlark output format#1445
Draft
fmeum wants to merge 4 commits into
Draft
Conversation
HT154
reviewed
Feb 26, 2026
HT154
left a comment
Contributor
There was a problem hiding this comment.
Hi there! We generally encourage renderer development to be done in Pkl code to avoid increasing the API surface and maintenance cost of the core language. Pkl code may subclass ValueRenderer and directly implement its methods. This is how the TOML renderer is implemented: https://github.com/apple/pkl-pantry/tree/main/packages/pkl.toml. It would be much easier for us to accept a contribution of that nature.
* Add `starlark.Commented`, which attaches `#`-prefixed comment lines to the rendered form of a top-level statement. * Render top-level `RenderDirective`s verbatim instead of as assignments so that raw statements such as `load()` can be emitted. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Classes annotated with `@starlark.Load { label = "..." }` contribute a
`load()` statement to the top of the rendered document whenever an
instance is rendered. Statements are deduplicated per label, sorted by
label, and load the annotated classes' simple names.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replaces the plain lexical sort with a port of buildtools' `compareLoadLabels`/`comparePaths`: labels with an explicit repository go first, the empty package precedes named packages, packages and file names compare segment-wise and case-insensitively, and relative labels go last. Verified against `buildifier --mode=diff`, which leaves the rendered output unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TODO:
Pair(tuple)loadlabel, collect the labels for all classes in the module and emit them at the top