pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Triple dot module uri resolution for local dependencies

Open jw-y opened this issue 1 year ago • 2 comments

Not sure if I am doing something wrong, but here it goes.

Here is the file structure

base
| - foo.pkl
| - PklProject
| - bar
   | -  baz
      | -  bar.pkl 
derive
| - tmp.pkl
| - PklProject

Summary

Basically, if it try to import and initialize with import "@base/bar/baz/bar.pkl" in derive/tmp.pkl where base/bar/baz/bar.pkl imports base/foo.pkl with triple dot syntax (extends ".../foo.pkl") it gives following error

–– Pkl Error ––
I/O error loading module `projectpackage://github.com/[email protected]#/bar/foo.pkl`.
NoSuchFileException: /home/jwyang/test_pkl/derive/../base/bar/foo.pkl

3 | foo = new bar{}
              ^^^
at tmp#foo (file:///home/jwyang/test_pkl/derive/tmp.pkl, line 3)

106 | text = renderer.renderDocument(value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.2/stdlib/base.pkl#L106)

Files

base/PklProject

amends "pkl:Project"
local github_path = "github.com"
package = new {
    name= "foo"
    baseUri="package://\(github_path)/pkl"
    version= "0.1.0"
    packageZipUrl="https://\(github_path)/"
    exclude {
        "tests"
        "tests/**"
    }
}

base/foo.pkl

abstract module foo
var = "Hi"

base/bar/baz/bar.pkl

module bar
extends ".../foo.pkl"

derive/PklProject

amends "pkl:Project"
dependencies {
  ["base"]= import(".../base/PklProject")
}

derive/tmp.pkl

import "@base/bar/baz/bar.pkl"
foo = new bar{}

Commands

cd derive
pkl project resolve
pkl eval tmp.pkl  # this throws above error

Resulting PklProject.deps.json

{
  "schemaVersion": 1,
  "resolvedDependencies": {
    "package://github.com/pkl@0": {
      "type": "local",
      "uri": "projectpackage://github.com/[email protected]",
      "path": "../base"
    }
  }
}

If I replace triple dot syntax in base/bar/baz/bar.pkl with extends "../../foo.pkl" error doesn't show anymore

jw-y avatar Mar 15 '24 09:03 jw-y

Thanks! Looks like a bug.

bioball avatar Mar 15 '24 23:03 bioball