-
I'm trying to generate JSON from Firstly, I tried to extract the current file's URI by loading it as % cat t1.pkl
__file__ = let (uri = read("...").uri) (
uri.substring(uri.indexOf(":")+1, uri.length).replaceAll(Regex(#"/+/"#), "/")
)
% pkl eval --format=json t1.pkl
–– Pkl Error ––
Cannot find resource `...`.
1 | __file__ = let (uri = read("...").uri) (
^^^^^^^^^^^
at t1#__file__ (file:///private/tmp/pkltest/t1.pkl, line 1)
106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.3/stdlib/base.pkl#L106) I could get the directory name by reading % cat t2.pkl
__file__ = let (uri = read(".").uri) (
uri.substring(uri.indexOf(":")+1, uri.length).replaceAll(Regex(#"/+/"#), "/")
)
% pkl eval --format=json t2.pkl
{
"__file__": "/private/tmp/pkltest/"
} Is there anybody who can manage to get the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You can get the URI of the current module using Line 197 in 309e3ff |
Beta Was this translation helpful? Give feedback.
-
Thanks for swift answer 🙇 I have confirmed that % cat t3.pkl
import "pkl:reflect"
__file__ = let (uri = reflect.Module(this).uri) (
uri.substring(uri.indexOf(":")+1, uri.length).replaceAll(Regex(#"/+/"#), "/")
)
% pkl eval --format=json t3.pkl
{
"__file__": "/private/tmp/pkltest/t3.pkl"
} |
Beta Was this translation helpful? Give feedback.
You can get the URI of the current module using
pkl:reflect
. Here's an example in the stdlib:pkl/stdlib/Project.pkl
Line 197 in 309e3ff