Properties reader should be loaded for pkl project package #305

Closed
opened 2025-12-30 01:23:20 +01:00 by adam · 2 comments
Owner

Originally created by @discount-elf on GitHub (Apr 26, 2025).

It would be useful to be able to do the following:

pkl project package -p 'version=1.0.1'

PklProject

package {
  name = "somepkg"
  baseUri = "package://example.com/pkl/\(name)/\(name)"
  version = read("prop:version")
  packageZipUrl = "https://example.com/pkl/\(name)/\(name)@\(version).zip"
}

Currently pkl 0.28.1 complains about the prop module reader not being present. I couldn't get it working tweaking any combination of --allowed-resources and --allowed-modules

Originally created by @discount-elf on GitHub (Apr 26, 2025). It would be useful to be able to do the following: `pkl project package -p 'version=1.0.1'` PklProject ```pkl package { name = "somepkg" baseUri = "package://example.com/pkl/\(name)/\(name)" version = read("prop:version") packageZipUrl = "https://example.com/pkl/\(name)/\(name)@\(version).zip" } ``` Currently pkl `0.28.1` complains about the prop module reader not being present. I couldn't get it working tweaking any combination of `--allowed-resources` and `--allowed-modules`
adam closed this issue 2025-12-30 01:23:20 +01:00
Author
Owner

@bioball commented on GitHub (May 7, 2025):

We don't allow external properties when loading PklProject because that module is somewhat special; it's a manifest that controls Pkl evaluation in a normal program. E.g. through evaluatorSettings:

amends "pkl:Project"

evaluatorSettings {
  externalProperties {
    ["foo"] = "bar"
  }
}

When you eval another module, the PklProject first gets evaluated, and any settings therein are applied to the rest of the evaluation. We want external properties to specifically be an input to a "normal" program.

If you want to set the version from an external source, you have two choices:

  1. Read environment variables (e.g. version = read("env:VERSION"))
  2. Read a file (e.g. version = read("VERSION.txt").text.trim())

I'd recommend the second approach, because this allows IDEs to run the sync projects action.

@bioball commented on GitHub (May 7, 2025): We don't allow external properties when loading `PklProject` because that module is somewhat special; it's a manifest that _controls_ Pkl evaluation in a normal program. E.g. through `evaluatorSettings`: ```pkl amends "pkl:Project" evaluatorSettings { externalProperties { ["foo"] = "bar" } } ``` When you eval another module, the `PklProject` first gets evaluated, and any settings therein are applied to the rest of the evaluation. We want external properties to specifically be an input to a "normal" program. If you want to set the version from an external source, you have two choices: 1. Read environment variables (e.g. `version = read("env:VERSION")`) 2. Read a file (e.g. `version = read("VERSION.txt").text.trim()`) I'd recommend the second approach, because this allows IDEs to run the sync projects action.
Author
Owner

@discount-elf commented on GitHub (May 7, 2025):

Ah got it. Yes I was using the second approach before filing! Thank you!

@discount-elf commented on GitHub (May 7, 2025): Ah got it. Yes I was using the second approach before filing! Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#305