Support scheme-agnostic projects (#486)

This adds changes to support loading project dependencies in non-file based projects.

The design for this feature can be found in SPICE-0005: https://github.com/apple/pkl-evolution/pull/6

Changes:
* Consider all imports prefixed with `@` as dependency notation.
* Bugfix: fix resolution of glob expressions in a local dependency.
* Adjust pkl.Project:
  - Allow local dependencies from a scheme-local paths.
  - Disallow certain evaluator settings if not loaded as a file-based module.
* Breaking API change: `ProjectDependenciesManager` constructor now requires `ModuleResolver` and `SecurityManager`.
This commit is contained in:
Daniel Chao
2024-06-04 16:52:20 -07:00
committed by GitHub
parent c0a7080287
commit d5ba8fa736
49 changed files with 764 additions and 235 deletions
@@ -11,4 +11,5 @@ dependencies {
uri = "package://localhost:0/badImportsWithinPackage@1.0.0"
}
["project2"] = import("../project2/PklProject")
["project6"] = import("../project6/PklProject")
}
@@ -20,6 +20,11 @@
"uri": "projectpackage://localhost:0/project2@1.0.0",
"path": "../project2/"
},
"package://localhost:12110/project6@1": {
"type": "local",
"uri": "projectpackage://localhost:12110/project6@1.0.0",
"path": "../project6/"
},
"package://localhost:0/badImportsWithinPackage@1": {
"type": "remote",
"uri": "projectpackage://localhost:0/badImportsWithinPackage@1.0.0",
@@ -34,4 +34,8 @@ examples {
["glob-read absolute package uri"] {
read*("package://localhost:0/birds@0.5.0#/catalog/*.pkl")
}
["glob-import behind local project import"] {
import("@project6/children.pkl")
}
}
@@ -20,6 +20,11 @@
"uri": "projectpackage://localhost:0/project2@1.0.0",
"path": "../project2/"
},
"package://localhost:12110/project6@1": {
"type": "local",
"uri": "projectpackage://localhost:12110/project6@1.0.0",
"path": "../project6/"
},
"package://localhost:0/badImportsWithinPackage@1": {
"type": "remote",
"uri": "projectpackage://localhost:0/badImportsWithinPackage@1.0.0",
@@ -0,0 +1,8 @@
amends "pkl:Project"
package {
name = "project6"
baseUri = "package://localhost:12110/project6"
version = "1.0.0"
packageZipUrl = "https://localhost:12110/project6/project6-\(version).zip"
}
@@ -0,0 +1,4 @@
{
"schemaVersion": 1,
"resolvedDependencies": {}
}
@@ -0,0 +1 @@
children = import*("children/*.pkl")
@@ -0,0 +1 @@
name = "a"
@@ -0,0 +1 @@
name = "b"
@@ -0,0 +1 @@
name = "c"
@@ -1,13 +1,13 @@
–– Pkl Error ––
Expected value of type `*RemoteDependency|LocalDependency`, but got a different `pkl.Project`.
Expected value of type `*RemoteDependency|Project(isValidLoadDependency)`, but got a different `pkl.Project`.
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetting...
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency|LocalDependency>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
xxx | dependencies: Mapping<String(!contains("/")), *RemoteDependency|Project(isValidLoadDependency)>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.Project#dependencies (pkl:Project)
* Value is not of type `LocalDependency` because:
Type constraint `this.package != null` violated.
* Value is not of type `Project(isValidLoadDependency)` because:
Type constraint `isValidLoadDependency` violated.
Value: new ModuleClass { package = null; tests {}; dependencies {}; evaluatorSetti...
x | dependencies {
@@ -1,8 +1,9 @@
–– Pkl Error ––
Cannot resolve dependency because file `PklProject.deps.json` is missing in project directory `file:///$snippetsDir/input/projects/missingProjectDeps/`.
Encountered an error when attempting to load `PklProject.deps.json` at `file:///$snippetsDir/input/projects/missingProjectDeps/PklProject.deps.json`.
NoSuchFileException: /$snippetsDir/input/projects/missingProjectDeps/PklProject.deps.json
x | import "@birds/Bird.pkl"
^^^^^^^^^^^^^^^^^
at bug (file:///$snippetsDir/input/projects/missingProjectDeps/bug.pkl)
Run `pkl project resolve` to create a new set of dependencies.
Try running `pkl project resolve` within the project directory to create a new set of dependencies.
@@ -262,4 +262,19 @@ examples {
}
}
}
["glob-import behind local project import"] {
new {
children {
["children/a.pkl"] {
name = "a"
}
["children/b.pkl"] {
name = "b"
}
["children/c.pkl"] {
name = "c"
}
}
}
}
}
@@ -0,0 +1,11 @@
children {
["children/a.pkl"] {
name = "a"
}
["children/b.pkl"] {
name = "b"
}
["children/c.pkl"] {
name = "c"
}
}
@@ -0,0 +1 @@
name = "a"
@@ -0,0 +1 @@
name = "b"
@@ -0,0 +1 @@
name = "c"