Skip to content

Add starlark output format#1445

Draft
fmeum wants to merge 4 commits into
apple:mainfrom
fmeum:starlark
Draft

Add starlark output format#1445
fmeum wants to merge 4 commits into
apple:mainfrom
fmeum:starlark

Conversation

@fmeum

@fmeum fmeum commented Feb 26, 2026

Copy link
Copy Markdown

TODO:

  • Add support for Pair (tuple)
  • Insert empty lines around top-level statements
  • Sort keyword arguments
  • Find a way to annotate classes with a Bazel load label, collect the labels for all classes in the module and emit them at the top

@HT154 HT154 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

fmeum and others added 3 commits June 11, 2026 16:00
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants