Improve handling of evaling dependency notation URIs (#1595)

This commit is contained in:
Daniel Chao
2026-05-15 15:51:09 -07:00
committed by GitHub
parent 3ad1cb3645
commit a7a64acbac
17 changed files with 123 additions and 156 deletions
@@ -1,5 +1,5 @@
–– Pkl Error ––
Cannot import dependency because there is no project found.
Cannot resolve dependency because there is no project found.
If you meant to import a path that starts with `@`, prefix the path with `./` (e.g. `import "./@myPath").
If you meant to import a dependency, ensure that this file is within a directory that contains a PklProject module.
@@ -507,7 +507,7 @@ class EvaluatorTest {
val evaluator = evaluatorBuilder.setProjectDependencies(project.dependencies).build()
assertThatCode { evaluator.use { it.evaluateOutputText(uri("foobar:baz")) } }
.hasMessageContaining(
"Cannot import dependency because project URI `foobar:foo/PklProject` does not have a hierarchical path."
"Cannot resolve dependency because project URI `foobar:foo/PklProject` does not have a hierarchical path."
)
}
@@ -722,6 +722,34 @@ class EvaluatorTest {
}
}
@Test
fun `eval dependency notation as a module source`(@TempDir tempDir: Path) {
PackageServer.populateCacheDir(tempDir)
val project = Project.load(modulePath("org/pkl/core/project/project5/PklProject"))
val evaluator =
with(EvaluatorBuilder.preconfigured()) {
moduleCacheDir = tempDir
applyFromProject(project)
build()
}
val outputText = evaluator.evaluateOutputText(uri("@fruit/catalog/apple.pkl"))
assertThat(outputText)
.isEqualTo(
"""
name = "Apple"
"""
.trimIndent()
)
}
@Test
fun `eval dependency notation -- no project configured`() {
val evaluator = Evaluator.preconfigured()
assertThatCode { evaluator.evaluateOutputText(uri("@fruit/catalog/apple.pkl")) }
.hasMessageContaining("Cannot resolve dependency because there is no project found.")
}
private fun checkModule(module: PModule) {
assertThat(module.properties.size).isEqualTo(2)
assertThat(module.getProperty("name")).isEqualTo("pigeon")