opaque uris and resources interaction #352

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

Originally created by @BenFradet on GitHub (Oct 24, 2025).

with 0.29, opaque uris are invalid: https://pkl-lang.org/main/current/release-notes/0.29.html#opaque-file-uris-are-invalid

the error message says:

–– Pkl Error ––
Resource URI `file:../path/.manifest.yml` has invalid syntax.

30 | const manifest = yamlParser.parse(read("file:../\(manifestPath)"))
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at Common#manifest (file:///pkl/Common.pkl, line 30)

File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).
To resolve relative paths, remove the scheme prefix (remove "file:").

However, read requires a Resource which mandates the file: prefix.

It is a bit awkward to do

const workingDirectory = read("env:PWD")
const manifest = yamlParser.parse(read("file:\(workingDirectory)/../\(manifestPath)"))

Are there any alternatives?

Originally created by @BenFradet on GitHub (Oct 24, 2025). with 0.29, opaque uris are invalid: https://pkl-lang.org/main/current/release-notes/0.29.html#opaque-file-uris-are-invalid the error message says: ``` –– Pkl Error –– Resource URI `file:../path/.manifest.yml` has invalid syntax. 30 | const manifest = yamlParser.parse(read("file:../\(manifestPath)")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ at Common#manifest (file:///pkl/Common.pkl, line 30) File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl). To resolve relative paths, remove the scheme prefix (remove "file:"). ``` However, `read` requires a [`Resource`](https://pkl-lang.org/main/current/language-reference/index.html#resources) which mandates the `file:` prefix. It is a bit awkward to do ``` const workingDirectory = read("env:PWD") const manifest = yamlParser.parse(read("file:\(workingDirectory)/../\(manifestPath)")) ``` Are there any alternatives?
adam closed this issue 2025-12-30 01:23:46 +01:00
Author
Owner

@bioball commented on GitHub (Oct 24, 2025):

Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path:

const manifest = yamlParser.parse(read("../\(manifestPath)"))
@bioball commented on GitHub (Oct 24, 2025): Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path: ```pkl const manifest = yamlParser.parse(read("../\(manifestPath)")) ```
Author
Owner

@HT154 commented on GitHub (Oct 24, 2025):

If you do truly want to read relative to the working directory, here's how to do it in a robust, cross-platform way:

7a8db5d291/packages/k8s.contrib.crd/generate.pkl (L98-L107)

@HT154 commented on GitHub (Oct 24, 2025): If you do truly want to read relative to the working directory, here's how to do it in a robust, cross-platform way: https://github.com/apple/pkl-pantry/blob/7a8db5d291bd91b0a1cd0fcc3e6284a167968abf/packages/k8s.contrib.crd/generate.pkl#L98-L107
Author
Owner

@BenFradet commented on GitHub (Oct 27, 2025):

Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path:

const manifest = yamlParser.parse(read("../(manifestPath)"))

this doesn't work, it fails with:

–– Pkl Error ––
Cannot find resource `../path/manifest.yml`.

The prefix in Resource might me mandatory?

@BenFradet commented on GitHub (Oct 27, 2025): > Is that resource at a relative path to your Pkl file? If so, you'd just pass in the relative path: > > const manifest = yamlParser.parse(read("../\(manifestPath)")) this doesn't work, it fails with: ``` –– Pkl Error –– Cannot find resource `../path/manifest.yml`. ``` The prefix in [Resource](https://pkl-lang.org/main/current/language-reference/index.html#resources) might me mandatory?
Author
Owner

@HT154 commented on GitHub (Oct 27, 2025):

The prefix in Resource might me mandatory?

It is not. Reading with relative path reads relative to the module the read is in. If you are intending to read relative to the working directory, you need to use the more verbose invocation I linked above.

@HT154 commented on GitHub (Oct 27, 2025): > The prefix in Resource might me mandatory? It is not. Reading with relative path reads relative to the module the `read` is in. If you are intending to read relative to the working directory, you need to use the more verbose invocation I linked above.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#352